Skip to main content
Outlook webhooks are delivered through Microsoft Graph change notifications: you create a subscription on a mailbox resource (messages, events, or contacts) with your Nango webhook URL as the notificationUrl, and Microsoft Graph posts a notification there whenever that resource changes.

How it works

  1. You create a Microsoft Graph subscription for the resource you want to watch (e.g. inbox messages), passing your Nango webhook URL as notificationUrl and a clientState secret.
  2. Microsoft Graph validates the URL by sending it a validationToken — Nango handles this handshake automatically, so you don’t need to implement it yourself.
  3. When the resource changes, Microsoft Graph sends a POST request with one or more notifications to your Nango webhook URL, each carrying the clientState you set, the subscriptionId you got back when creating the subscription, and a resource path identifying what changed.
  4. Nango verifies clientState against your integration’s Webhook secret, matches the notification to a connection using its subscriptionId, 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

  1. In the Nango dashboard, open your Outlook integration and go to the Settings tab.
  2. Enter a secret string in the Webhook Secret field. You’ll pass this same value as clientState when creating subscriptions in the next step.
Nango rejects any webhook received where the clientState does not match the integration Webhook Secret.

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.
You can also do this manually:
Replace:
  • 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.
See the API reference for the exact request shape and other watchable resources.

4. Renew the subscription

Microsoft Graph does not renew subscriptions automatically. Before a subscription expires, send a PATCH 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 a pre-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 webhookSubscriptions and onWebhook in a sync script. See Real-time syncs.
A single delivery’s body is a changeNotificationCollection — an array of notifications under value, since Microsoft Graph batches notifications for the same notificationUrl:
Notifications carry only the id of the changed object, not its content — call the Graph API (e.g. 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 the subscriptionId 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:
To do this in bulk, iterate over the list connections response and update the metadata for each one.
Setting metadata.subscriptionIds replaces the array — if the connection already has other subscription ids stored, include them in the request too or you’ll orphan those subscriptions (they’ll keep running, but notifications for them will stop matching a connection).
If Nango cannot match the incoming notification’s subscriptionId to a connection, the webhook is still forwarded but won’t include a connectionId in the payload. If more than one connection lists the same subscription id, the webhook is forwarded once per matching connection.

Rollback strategy

To stop webhooks, delete the subscription using the id Microsoft Graph returned when you created it:
Or let the subscription expire by not renewing it. Either way, also remove the id from 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.
Need help getting started? Join us in the community.