iTranslated by AI
Receiving Microsoft Graph Change Notifications with Microsoft Flow
Introduction
Microsoft Graph allows you to receive change notifications via webhooks. Judging from the access permissions, it seems intended for organizational management rather than personal use, but I decided to check if it could also be received in Microsoft Flow. This time, I will introduce how to receive change notifications for users.
Creating the Flow
Flow to receive change notifications
When creating a subscription to receive change notifications, you must return the validationToken sent by Microsoft Graph to verify the URL.
Microsoft Graph sends a POST request to the notification URL:
POST https://{notificationUrl}?validationToken={TokenDefinedByMicrosoftGraph}
The client must provide a response with the following characteristics within 10 seconds:
A 200 (OK) status code.
The content type must be text/plain.
The body must include the validation token provided by Microsoft Graph.
Because of this, I branch the process depending on whether the query string contains the validationToken. If it contains the validationToken, I return a response that meets the specifications above. If it does not, it is treated as an actual change notification, so I receive the ID, fetch the user information, and send that information via email.


Flow to create a subscription
The subscription endpoint is /subscriptions, which is not common across the entire organization but is instead defined per user or application. To automate the renewal of subscriptions, which I will discuss later, it is necessary to use Application permissions (Client Credentials Grant), so the creation of the subscription is performed in the same way.
The following article is also helpful for learning how to create the flow.
For the notificationUrl, specify the URL of the flow that receives change notifications.

Flow to renew the subscription
Subscriptions have an expiration date (maximum 3 days), and if they are not renewed, they are automatically deleted. To receive change notifications continuously, you need to run a flow once a day on a schedule to renew the expiration date.

Conclusion
Since this can be implemented in Microsoft Flow, it can be built in the same way in Logic Apps. In terms of functionality, implementation in Logic Apps may be suitable in some cases. If you require custom processing for receiving change notifications, please consider switching to Azure Functions.
Discussion