Creating Subscription through Postman throws error - microsoft-graph-api

Creating WebHook for MicrosoftGraph throws error
What is ClientState represents ?
{
"changeType": "updated",
"clientState": "kT]G=3#hClz0rRfOuVr*3UA8V_9UGs4p",
"expirationDateTime": "2019-09-26T15:46:18.835Z",
"notificationUrl": "https://webhooksformicrosoftgraph.azurewebsites.net/api/HttpTrigger1",
"resource": "groups"
}
{
"error": {
"code": "InvalidRequest",
"message": "Subscription validation request failed. Must respond with 200 OK to this request.",
"innerError": {
"request-id": "4f368e23-9a5d-4c72-a2cf-9bbe33f677f4",
"date": "2019-09-23T06:35:20"
}
}
}

We have a great tutorial on setting up your first change notification (web hook). You may want to run through this first
https://learn.microsoft.com/en-us/graph/tutorials/change-notifications
Basically your API that our web hook calls needs to return 200 OK on first registering a subscription for our service to validate your API.

Related

Microsoft Graph API - Using postman to update the created task in microsoft planner

I am trying to update the task in Microsoft planner using Graph API in postman. I have already created a blank task and I am updating the created task using PATCH function to attach a file.
PATCH Request:
PATCH https://graph.microsoft.com/v1.0/planner/tasks/{task-id}/details
Content-type: application/json
Prefer: return=representation
If-Match: W/\"JzEtVGFza0RldGFpbHMgQEBAQEBAQEBAQEBAQEBAVCc=\"
{
"#odata.etag": "W/\"JzEtVGFza0RldGFpbHMgQEBAQEBAQEBAQEBAQEBAVCc=\"",
"previewType": "noPreview",
"references": {
"https%3A//my%2Esharepoint%2Ecom/sites/Test12/Shared Documents/Sample%2Edocx":
{
"#odata.type": "microsoft.graph.plannerExternalReference",
"alias": "Sample.docx",
"lastModifiedBy": {
"user": {
"id": "5442777a-0440-4a2f-9269-21824464e3a1"
}
},
"lastModifiedDateTime": "2022-09-05T11:06:47.6011074Z",
"previewPriority": "0009005756397228702",
"type": "word"
}
}
}
When i sent it it showed 400 Bad Request.
Response Error Message -
{
"error": {
"code": "",
"message": "The request is invalid:\r\nAn unexpected 'StartObject' node was found for property named 'lastModifiedBy' when reading from the JSON reader. A 'PrimitiveValue' node was expected.",
"innerError": {
"date": "2022-09-06T04:49:34",
"request-id": "37001992-fafb-461e-a4f0-9f1dafa34b21",
"client-request-id": "37001992-fafb-461e-a4f0-9f1dafa34b21"
}
}
}
Is there any issue with the body content?

Microsoft ToDo Graph API is sending broken JSON

I'm getting the response with invalid JSON (brackets aren't closed) when trying to get the MS ToDo task for the user. Also, API sends HTTP status 200 with that response.
Request/response examples:
https://graph.microsoft.com/v1.0/me/todo/lists/:listID/tasks/:taskID
{
"title": "DELETED",
"createdDateTime": "2020-06-17T18:33:44.3228459Z",
"lastModifiedDateTime": "2020-11-27T11:36:55.8037415Z",
"id": "DELETED",
"linkedResources": [
{
"error": {
"code": "InternalServerError",
"message": "Invalid object within the collection response from workload for navigation property linkedResources with declaring type microsoft.graph.todoTask. Expected a JObject, but got Jtoken type - Null",
"innerError": {
"date": "2021-05-14T03:13:36",
"request-id": "5b9445b0-7405-436a-8179-cac92a8af087",
"client-request-id": "5b9445b0-7405-436a-8179-cac92a8af087"
}
}
}
How can I resolve this issue?

Bad Request: Invalid filter clause

I am using POSTMAN to call Microsoft Graph APIs. I am trying to subscribe to presence for multiple users. It is mentioned in document in order to subscribe to changes to multiple user presences use this url :/communications/presences?$filter=id in ({id},{id}...)
Request Url
https://graph.microsoft.com/beta/subscriptions
So this is request body(raw)
{
"changeType": "updated",
"notificationUrl": "https://d3a8ebc3581d.ngrok.io/presence-notify/",
"resource": "/communications/presences?$filter=id in (abcd-efgh-4856-a935-c9a2f685xyz,abcd-efgh-47f8-9d79-eacb0fd6xyz)",
"expirationDateTime": "2020-09-22T07:37:13Z",
"clientState": "secretClientState"
}
I am calling this API on behalf of user i.e i am using UserAccessToken. This is Response:
{
"error": {
"code": "BadRequest",
"message": "Invalid filter clause",
"innerError": {
"date": "2020-09-21T16:24:50",
"request-id": "2cf476f0-2270-417f-a987-5c5bbc92a351",
"client-request-id": "2cf476f0-2270-417f-a987-5c5bbc92a351"
}
}
}
P.S: I have changed first few and last few characters of both the user ids. So it's not an issue.
I'm guessing this isn't documented very clearly, but if you check the filter documentation. You'll see that values actually need to have ' around them.
So if you change your request to the following it should work:
{
"changeType": "updated",
"notificationUrl": "https://d3a8ebc3581d.ngrok.io/presence-notify/",
"resource": "/communications/presences?$filter=id in ('abcd-efgh-4856-a935-c9a2f685xyz','abcd-efgh-47f8-9d79-eacb0fd6xyz')",
"expirationDateTime": "2020-09-22T07:37:13Z",
"clientState": "secretClientState"
}

microsoft graph api - Cannot create mail subscription error: ServiceUnavailable

When we were trying to create a email subscription with an email account, we got the ServiceUnavailable error.
POST https://graph.microsoft.com/v1.0/subscriptions
Body: {
"changeType": "created",
"notificationUrl": "***********************",
"resource": "me/messages",
"expirationDateTime":"2019-09-11T18:23:45.9356913Z",
"clientState": "****"
}
Response is
{
"error":{
"code": "ExtensionError",
"message": "Operation: Create; Exception: [Status Code: ServiceUnavailable; Reason: Target resource '0003bffd-d62b-a260-0000-000000000000' hosted on database '8cea8e2c-3c39-469c-a9e7-3f0bed47d869' is currently on backend 'Unknown']",
"innerError":{
"request-id": "972e7800-541e-41f9-8792-069ecd564345",
"date": "2019-09-09T23:30:13"
}
}
}
What could be the reason for this kind of error?

Unable to subscribe to rich notifications in MS Graph

How can I create a subscription with rich notifications in MS Graph?
POST https://graph.microsoft.com/v1.0/subscriptions
{
"resource": "users/{email}/messages?$select=hasAttachments",
"changeType": "created",
"clientState": "415e99b4-73af-454e-93b5-00eb6c3082b9",
"notificationUrl": "https://229c8207.ngrok.io/Notification/Listen",
"includeProperties": true,
"expirationDateTime": "2019-01-16T22:21:56.3942423+00:00"
}
Expected: 202 Created
Actual: 400 Bad Request
{
"error": {
"code": "InvalidRequest",
"message": "Microsoft.Exchange workload is not enabled for rich notifications.",
"innerError": {
"request-id": "7e03b3c9-aa49-4222-b7a7-5fddebc82327",
"date": "2019-01-16T16:47:24"
}
}
}
"Rich notifications" are not yet enabled through Microsoft Graph. We are working on it and will be adding some exciting new capabilities. We cannot provide an ETA at this time, but it is top of our list for this feature area.

Resources