notificationUrl, and Microsoft Graph posts a notification there whenever that resource changes.
How it works
- You create a Microsoft Graph subscription for the resource you want to watch (e.g. inbox messages), passing your Nango webhook URL as
notificationUrland aclientStatesecret. - Microsoft Graph validates the URL by sending it a
validationToken— Nango handles this handshake automatically, so you don’t need to implement it yourself. - When the resource changes, Microsoft Graph sends a POST request with one or more notifications to your Nango webhook URL, each carrying the
clientStateyou set, thesubscriptionIdyou got back when creating the subscription, and aresourcepath identifying what changed. - Nango verifies
clientStateagainst your integration’s Webhook secret, matches the notification to a connection using itssubscriptionId, and forwards the event to your app.
Connection routing relies on the subscription’s
id being recorded in metadata.subscriptionIds on the connection — the automation in step 3 below does this for you. See Connection matching for details.Setup
1. Get your Nango webhook URL
In the Nango dashboard, open your Outlook integration and copy the Webhook URL.2. Set a required webhook secret in Nango
- In the Nango dashboard, open your Outlook integration and go to the Settings tab.
- Enter a secret string in the Webhook Secret field. You’ll pass this same value as
clientStatewhen creating subscriptions in the next step.
3. Create a subscription (watch a resource)
Subscribing requires the same delegated permission you’d need to read the resource directly (e.g.,Mail.Read for messages, Calendars.Read for events, Contacts.Read for contacts). Add the scope to your Outlook integration’s Scopes field in the Nango dashboard and re-authorize the connection if it was created before the scope was added.
You can automate creating the subscription for new connections with a post-connection-creation script.
- notificationUrl — Your Nango webhook URL from the dashboard.
- resource — The mailbox resource to watch. Common values:
me/mailFolders('inbox')/messages(inbox messages),me/messages(all messages),me/events(calendar events),me/contacts(contacts). - clientState — The webhook secret from step 2.
- expirationDateTime — An ISO 8601 timestamp. Messages, events, and contacts support a maximum of 10,070 minutes from the time of subscription.
4. Renew the subscription
Microsoft Graph does not renew subscriptions automatically. Before a subscription expires, send aPATCH request with a new expirationDateTime; the subscription id and clientState stay the same. See Renew subscription.
You can use a Nango sync with a suitable frequency to renew subscriptions before they expire:
5. Delete the subscription on connection deletion
If a connection is deleted in Nango but the subscription remains active, Microsoft Graph keeps sending notifications until it expires. To stop them immediately, delete the subscription before the connection is removed. You can automate this with apre-connection-deletion lifecycle event:
Handle the webhook
Once routed to a connection, you have two options:- Forward it to your app — Nango forwards the event to your webhook URL with connection attribution. See External webhook forwarding.
- Process it in a sync — run a sync when the webhook arrives using
webhookSubscriptionsandonWebhookin a sync script. See Real-time syncs.
changeNotificationCollection — an array of notifications under value, since Microsoft Graph batches notifications for the same notificationUrl:
GET /v1.0/me/messages/{id}) to fetch what changed.
Supported events
Nango can route any subscription on the messages, events, or contacts resources.changeType (used as the webhook type for webhookSubscriptions/onWebhook) is one of:
For the full list of watchable resources (including shared mailboxes and other Microsoft Graph resources), see Microsoft’s subscription resource types reference.
Connection matching
Every Microsoft Graph notification carries thesubscriptionId of the subscription it came from. Nango matches that value against metadata.subscriptionIds — a customer-controlled array on the connection, since a single connection can have more than one active subscription (e.g. one for messages, one for events). The automation in step 3 (and step 4) appends to this array automatically, so no manual setup is needed as long as you use it.
If you created subscriptions another way (e.g. manually, or before adopting this array), add the subscription id to the connection’s metadata yourself:
Rollback strategy
To stop webhooks, delete the subscription using theid Microsoft Graph returned when you created it:
metadata.subscriptionIds (and metadata.subscriptionExpirations) so the renewal sync stops trying to renew the subscription. Re-enable notifications by creating a new subscription with the steps above.