3

I have a requirement that, I need to get notification whenever any calendar item is created/updated/deleted. I followed the Outlook push notification documentation to subscribe to calendar notifications.

I have successfully subscribed for calendar events. But whenever I create a new calendar, I am receiving notification twice. Below is the notification request data.

First notification request data:

{
    "value": [{
        "@odata.type": "#Microsoft.OutlookServices.Notification",
        "Id": null,
        "SubscriptionId": "OTA0N0MwQj==",
        "SubscriptionExpirationDateTime": "2017-09-27T05:30:49.6163119Z",
        "SequenceNumber": 1,
        "ChangeType": "Created",
        "Resource": "https://outlook.office.com/api/v2.0/Users('1520ed5a')/Events('AAMkADAzNDUxODY=')",
        "ResourceData": {
            "@odata.type": "#Microsoft.OutlookServices.Event",
            "@odata.id": "https://outlook.office.com/api/v2.0/Users('1520ed5a')/Events('AAMkADAzNDUxODY=')",
            "@odata.etag": "W/\"DwAAABYAAAB4h4N+ELBRSbQKq1A05YT8AADcUdIx\"",
            "Id": "AAMkADAzNDUxOD="
        }
    }]
}

Second notification request data:

{
    "value": [{
        "@odata.type": "#Microsoft.OutlookServices.Notification",
        "Id": null,
        "SubscriptionId": "OTA0N0MwQj==",
        "SubscriptionExpirationDateTime": "2017-09-27T05:30:49.6163119Z",
        "SequenceNumber": 2,
        "ChangeType": "Updated",
        "Resource": "https://outlook.office.com/api/v2.0/Users('1520ed5a')/Events('AAMkADAzNDUxODY=')",
        "ResourceData": {
            "@odata.type": "#Microsoft.OutlookServices.Event",
            "@odata.id": "https://outlook.office.com/api/v2.0/Users('1520ed5a')/Events('AAMkADAzNDUxODY=')",
            "@odata.etag": "DwAAABYAAAB4h4N+ELBRSbQKq1A05YT8AADcUdIy\"",
            "Id": "AAMkADAzNDUxOD="
        }
    }]
}

If you observe both requests data, in first request data it's showing ChangeType as Created and in second request data it's showing ChangeType as Updated.

Same behavior (getting notification twice) when I update or delete calendar.

Any Idea how to get rid of second notification?

MK446
  • 448
  • 6
  • 22
  • Why do you want to get rid of it? It looks like something is updating it immediately after you create it. – Jason Johnston Sep 20 '17 at 13:57
  • I want to get rid of it, because once I receive the push notification, i will sync calendar with our database calendar object. If I get notification twice, then this syncing logic will be executed twice, which is redundant. As you said, will assume something is updating the calendar immediately after we create it. But I am receiving notification twice, even when I edit or delete the calendar. – MK446 Sep 21 '17 at 04:59
  • I just tried this here to confirm, and I don't see this behavior. So whatever is updating things in your calendar seems to be specific to your setup. Your syncing logic should be handling create and update differently, right? So this shouldn't be causing an issue, since you should be first creating a record in your local store, then updating it? – Jason Johnston Sep 21 '17 at 14:49
  • It appears twice in case of attendees only. If you don't add any attendee it give only one notification. – Yawar Feb 28 '18 at 15:17

1 Answers1

1

This isn't the expected behavior and I've been unable to replicate it myself. My best guess is that you have some other system monitoring the calendar and automatically editing the calendar events. This would explain why you get an update almost immediately following your create action.

When it comes to syncing, would recommend making use of the /delta functionality from Microsoft Graph API. When you receive a notification, you would then simply pull the /delta and return only the records that have changed. If you're receiving a false notification this would eliminate duplicate processing since the result of your second /delta would be empty. If you there is a change, but not to a property you care about, you could then discard the result and eliminate any unnecessary writes to your data store.

Marc LaFleur
  • 31,987
  • 4
  • 37
  • 63
  • Is `/delta` supports `$filter` query parameter? – MK446 Oct 23 '17 at 05:54
  • There is support for filtering on Users and Groups in the `/beta` endpoint but not for calendars. On a calendar it will report any changes to that calendar. – Marc LaFleur Oct 23 '17 at 13:06