Handling Duplicate Notifications from Microsoft Graph API

Shahar Spencer 0 Reputation points
2024-12-15T13:58:06.4+00:00

Using the Microsoft Graph API to receive notifications for new emails results in duplicated notifications. For instance, the following logs show two calls for the same new email to the same subscription within a very short timeframe.

this is how i am creating my subscription:

{"changeType": "created",
                                    "notificationUrl": "https://shahak-inspector-report-api.azurewebsites.net/new_email_notification",
                                    "lifecycleNotificationUrl": "https://shahak-inspector-report-api.azurewebsites.net/lifecycle_notification",
                                    "resource": "/users/6ee997c0-7afe-4f7f-8f13-f73aea416a49/mailfolders('inbox')/messages",
                                    "expirationDateTime": "2024-12-18T08:00:00Z"
}

and these are the logs showing the duplication:

2024-12-15T11:44:06.207411684Z STARTING EMAIL_NOTIFICATION_ENDPOINT with uid 73d82a7d-337c-4578-be5b-56ef0a6be09d AT 2024-12-15 11:44:06.206849
2024-12-15T11:44:06.207429285Z Request params in new email notification endpoint:
2024-12-15T11:44:06.207435985Z Request body in new email notification endpoint: b'{"value":[{"subscriptionId":"82354e2f-8da8-4365-9c39-68cbb3f541e5","subscriptionExpirationDateTime":"2024-12-17T08:00:00+00:00","changeType":"updated","resource":"Users/6ee997c0-7afe-4f7f-8f13-f73aea416a49/Messages/AAMkADZjNjRiNjY0LTUyNDEtNGIwOC05OTJjLTE5M2UxNjk4OTRiZABGAAAAAACy2roVEm0JR6z84-_jK8p9BwAbNITQWeQiRLxYVD6PMpZ1AAAAAAEMAAAbNITQWeQiRLxYVD6PMpZ1AAAMU3yBAAA=","resourceData":{"@odata.type":"#Microsoft.Graph.Message","@odata.id":"Users/6ee997c0-7afe-4f7f-8f13-f73aea416a49/Messages/AAMkADZjNjRiNjY0LTUyNDEtNGIwOC05OTJjLTE5M2UxNjk4OTRiZABGAAAAAACy2roVEm0JR6z84-_jK8p9BwAbNITQWeQiRLxYVD6PMpZ1AAAAAAEMAAAbNITQWeQiRLxYVD6PMpZ1AAAMU3yBAAA=","@odata.etag":"W/\\"CQAAABYAAAAbNITQWeQiRLxYVD6PMpZ1AAAMUND4\\"","id":"AAMkADZjNjRiNjY0LTUyNDEtNGIwOC05OTJjLTE5M2UxNjk4OTRiZABGAAAAAACy2roVEm0JR6z84-_jK8p9BwAbNITQWeQiRLxYVD6PMpZ1AAAAAAEMAAAbNITQWeQiRLxYVD6PMpZ1AAAMU3yBAAA="},"clientState":null,"tenantId":"8998f7cd-32cb-4f63-a300-fc589ffddc86"}]}'
2024-12-15T11:44:06.207446186Z Notification for new email acknowledged at 2024-12-15 11:44:06.207005
2024-12-15T11:44:06.207454386Z FINISHED EMAIL_NOTIFICATION_ENDPOINT with uid 73d82a7d-337c-4578-be5b-56ef0a6be09d at 2024-12-15 11:44:06.207033, returning response to sender: 
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,852 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Akhil Nasalwai - MSFT 165 Reputation points Microsoft Vendor
    2024-12-19T11:52:46.4266667+00:00

    Hello Shahar Spencer,

    Thank you for contacting Microsoft!

    This can happen due to a few reasons, but one most common cause is that the notification endpoint isn't acknowledging the receipt of the notification quickly enough. Here are some steps you can take to troubleshoot and potentially resolve this:

    1.Acknowledge Notifications Promptly: Ensure that your endpoint acknowledges the receipt of the notification with a 2XX status code within 3 seconds. If Microsoft Graph doesn't receive this acknowledgement, it will resend the notification.

    2.Check for throttling: If your endpoint consistently fails to acknowledge notifications within the required timeframe, Microsoft Graph might throttle the notifications. Ensure your endpoint is optimized to handle the load and respond quickly.

    3.Review Logs: Look at your logs to see if there are any patterns or specific conditions under which the duplication occurs. This might help identify if there's a particular scenario causing the issue.

    4.Update code: Make sure your code handling the notifications is up-to-date and correctly implemented. Sometimes, inefficiencies or small bugs might cause delays in acknowledgment.

    5.Test with different Endpoints: If possible, test your subscription with a different endpoint to see if the issue persists. This can help determine if the problem is with the endpoint or the subscription itself.

    After all the checks mentioned above are done, if you are still encountering this error, I would recommend you to raise a support case with Microsoft Graph, a Support Engineer will be able to look into this issue and assist you better. You can raise support ticket from https://admin.microsoft.com/#/support/requests

    Hope this helps.

    If the answer is helpful, please click Accept Answer kindly upvote it. If you have any further questions about this answer, please click comment.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.