Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft Graph Webhook/Subscription, getting multiple post to my notificationUrl

Im trying to receive push notification on calendar events through microsoft graph

the notificationURL points to webservice which is running on NodeJS

subscription I have made has these options.

   {
   "changeType": "created,updated,deleted",
   "notificationUrl": "myurl",
   "resource": "users/userid/events?$filter=sensitivity%20eq%20%27Normal%27",
   "expirationDateTime":"2016-11-05T18:23:45.9356913Z",
   "clientState": "customclientstate"
}

however im getting multiple POST calls(2~4) coming from subscription(all of them having identical body) whenever a single event is changed.

there is only one subscription active, a single calendar, and i am responding to the request with status code 204 without any content(tested with postman).

its a huge problem since im updating DB whenever the request comes in.

has anyone run into this problem? ive been looking all over without any results.

any input would be greatly appreciated!! =).

like image 602
JuHyun Lee Avatar asked Nov 03 '16 22:11

JuHyun Lee


People also ask

What is the purpose of the clientState property when creating a new change notification subscription?

Although clientState is not required, you must include it to comply with our recommended change notification handling process. Setting this property will allow you to confirm that change notifications you receive originate from the Microsoft Graph service.

What information is included in the payload of Microsoft Graph change notifications?

Microsoft Graph allows apps to subscribe to change notifications for resources via webhooks. You can set up subscriptions to include the changed resource data (such as the content of a Microsoft Teams chat message or Microsoft Teams presence information) in change notifications.

What are Delta queries?

Delta query enables applications to discover newly created, updated, or deleted entities without performing a full read of the target resource with every request. Microsoft Graph applications can use delta query to efficiently synchronize changes with a local data store.


1 Answers

I have this same issue. When creating new event in office calendar I'll get everytime one notification with ChangeType: Created and at the same time three notifications with ChangeType: Updated. When I'm cancelling event in office I get always 3 x Updated notifications and finally 1 x ChangeType: Deleted.

What you can do here is to use ChangeKey validation. Everytime you get new notification from office you have to request that event from API, right?

Once you fetched that event you can check if event.ChangeKey property has changed.

It's same thing as etag in websites. If content changes, etag hash changes.

So when you get Created notification, take that event's ChangeKey and store it to array or db and whenever you get notification remember to validate if you have that event's ID already in array or db and also if ChangeKey has changed. If ChangeKey is same as last time, you won't need to update that event in db.

This also works with recurring events, if even one occurrence has changed SeriesMaster event's ChangeKey also changes.

like image 121
lehtu Avatar answered Nov 03 '22 08:11

lehtu