Error using Invoke Request. Required property is submitted but not recognized

Lautaro B 0 Reputation points
2023-05-11T15:05:49.89+00:00

While trying to add a subscription for a test M365 APP, I get an error that says that a required property was not submitted. However, the cause of the error must be something else, since I make sure to submit the property in question.

Invoke-RestMethod: {"error":{"code":"InvalidRequest","message":"expirationDateTime is a required property for subscription creation.","innerError":{"date":"2023-05-11T14:47:14","request-id":"d616eae2-bd78-????-9d59-?????cafeb","client-request-id":"?????eae2-b?78-41e3-9d??-789a???afeb"}}} (the ? sign means characters that have been substituted for privacy reasons)

This is the instruction:

$subscription = Invoke-RestMethod -Uri $graphUrl -Method POST -Headers $headers -Body $JsonB2

## And this is the value of JsonB2:
PS C:\Users\myuser> $JsonB2 = '{"notificationUrl": "https://MyApp_test.azurewebsites.net/api/notifications",
    "resource": "me/mailboxSettings/autoReplySettings",
    "changeType": "updated",
    "expirationDateTime": "2023-05-11T15:44:58.0930264Z"}'
PS C:\Users\myuser> 
PS C:\Users\myuser> $JsonB2 | Test-Json
True
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
846 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. VasimTamboli 4,785 Reputation points
    2023-05-11T19:52:42.32+00:00

    The error message suggests that the expirationDateTime property is required for subscription creation but is not being recognized in your request. However, based on the JSON you provided, it appears that you are including the expirationDateTime property in the request body.

    One possibility is that there might be a formatting issue with the expirationDateTime value. Ensure that the date and time format adhere to the required format for the API you are calling. Double-check that the format is correct, including the presence of the "Z" at the end to indicate the UTC time zone.

    Another possibility is that there might be an issue with the API or service you are interacting with. It's worth verifying the API documentation or contacting the service provider for further assistance.

    Additionally, you can check if any other required properties are missing in the request. Review the API documentation or documentation specific to the service you are integrating with to ensure that you are including all the required properties and their values correctly.

    If the issue persists, it might be helpful to provide more details about the API or service you are working with, as well as any additional relevant code or error messages you receive, to assist in troubleshooting the issue further.

    1 person found this answer helpful.