How it works
- You create a Microsoft Graph subscription for each resource you want to watch, for example
me/messagesandme/events, with your Nango webhook URL as thenotificationUrl. - Graph sends a POST request to that URL when the resource changes. Every notification carries the subscription’s
clientStateandsubscriptionId. - Nango drops notifications whose
clientStatedoes not match the integration’s webhook secret, and removesclientStatebefore routing. - Nango routes each notification to the connection whose
metadata.subscriptionIdscontains itssubscriptionId, usingchangeType(orlifecycleEvent) as the webhook type.
subscriptionId.
Graph-based integrations
The same setup works for integrations built on Microsoft Graph whose resources support change notifications. Follow the steps below on that integration, and in step 3 use its resource, change types, and permission:
Drive items, including Word, Excel, and PowerPoint files, only support
updated, and a notification says that something changed in the drive, not which file. Use delta to fetch the changed files, for example from a sync triggered by the webhook.
Outlook has its own webhooks guide, and Microsoft Teams verifies requests differently.
Setup
1. Get your Nango webhook URL
In the Nango dashboard, open your Microsoft integration and copy the Webhook URL.2. Set the webhook secret in Nango
On the same page, set a Webhook secret, for example generated withopenssl rand -hex 32. Nango requires it and rejects every notification while it is empty. You pass the same value as clientState in the next step.
3. Subscribe when a connection is created
Create one Graph subscription per resource you want to watch, and store each subscriptionid in the connection’s metadata.subscriptionIds. The examples watch me/messages. Repeat with me/events for calendar events, and give the connection the matching read permission, for example Mail.Read or Calendars.Read.
Graph validates the URL with a validationToken request when you create a subscription, and Nango answers it automatically.
- Event function
- API
Subscribe new connections with a post-connection-creation function:
4. Renew the subscriptions
Graph subscriptions expire, and Graph doesn’t renew them. Check the maximumexpirationDateTime per resource in Microsoft’s docs, and extend each subscription before then.
- Sync
- API
Run a daily sync that extends every subscription in Graph also sends a
metadata.subscriptionIds:reauthorizationRequired lifecycle notification when a subscription needs attention. You can handle it in a sync’s onWebhook to renew right away.5. Unsubscribe when a connection is deleted
Delete a connection’s subscriptions before the connection itself, so Graph stops sending its notifications.- Event function
- API
Handle the webhook
Once routed, you have two options:- Forward it to your app: Nango forwards the notification to your webhook URL with connection attribution. See External webhook forwarding.
- Process it in a sync: run a sync when the webhook arrives using
webhookSubscriptionsandonWebhook. Subscribe tocreated,updatedordeleted, and to lifecycle events such asreauthorizationRequiredto renew subscriptions. For change notifications, use theresourcefield, for exampleUsers/<id>/Messages/<id>orUsers/<id>/Events/<id>, to tell mail and calendar apart. Lifecycle notifications have noresource: use theirsubscriptionIdto find the subscription. See Real-time syncs.
subscriptionId, Nango still forwards it, but separately and without a connectionId. Subscription validation requests are answered but never forwarded.
Rollback strategy
Delete each subscription as in step 5, then remove its ID from the connection’smetadata.subscriptionIds.