0

I am using Microsoft graph API and trying to create a subscription on the Microsoft developer portal.

https://graph.microsoft.com/v1.0/subscriptions I am hitting this URL with post request call as shown below

`

import requests

access_token = "testtoken"
subscription_data = {
    "changeType": "created,updated",
    "notificationUrl": "WEBHOOK URL",
    "resource": "me/contacts",
    "expirationDateTime": '2023-01-16T16:58:00.0000000Z'
}

headers = {
    'Authorization': 'Bearer ' + access_token,
    'Content-Type': 'application/xml'
}
try:
    response = requests.post(f'https://graph.microsoft.com/v1.0/subscriptions', json=subscription_data, headers=headers)
except Exception as e:
    print("error")

Above code is giving wrong message response as

 `{
        "error": {
            "code": "InvalidRequest",
            "message": "Could not process subscription creation payload. Are all property names spelled and camelCased properly?Also are the dateTimeOffest properties in a valid internet Date and Time format?",
            "innerError": {
                "date": "2023-01-14T19:09:17",
                "request-id": "6d50105e-08b1-494d-8400-5fc32909a8d1",
                "client-request-id": "c89e988f-783b-daf5-7d95-677002b0c22d"
            }
        }
    }
    `

As you see all property are in camelcase and date format is also in 8601 iso format, still getting errors and not able to create a subscription . I also saw similar problem faced and discussed here https://github.com/microsoftgraph/microsoft-graph-docs/issues/3041 however this is also not giving explanations how to solve the problem

3
  • Your resource parameter name has a wayward newline in it. See how the " is on the next line? It should be "resource": "me/messages",, all on the same line. Commented Jan 14, 2023 at 19:35
  • I am also make sure that I am creating subscription < 3 days in expirationDateTime as graph api suggest for each resource type possible subscription time Commented Jan 14, 2023 at 19:35
  • thanks @ceejayoz just updated that during format of code block it moved to next line. However thats good . changed to contacts resource endpoint Commented Jan 14, 2023 at 19:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.