Search code examples
azureazure-active-directorymicrosoft-graph-api

Not receiving Microsoft Graph change notification


I'd like to subscribe to user deletions, so that whenever a user is deleted in Azure AD, our app can react accordingly.

Here's my subscription request:

const now = new Date();
const threeDaysLater = new Date(now.getTime() + 3 * 24 * 58 * 60 * 1000);
request.post({
  auth: {
    bearer: {...},
  },
  headers: {
    Accept: 'application/json',
  },
  json: {
    changeType: 'updated,deleted',
    clientState: {...},
    expirationDateTime: threeDaysLater.toISOString(),
    notificationUrl: 'https://{...}.ngrok.io/api/azure/webhook',
    resource: 'users',
    latestSupportedTlsVersion: 'v1_2',
  },
  url: 'https://graph.microsoft.com/v1.0/subscriptions',
});

After sending this request, I receive a request to my notificationUrl, which I respond back to with the validation token.

I then receive the following response from the initial request:

{
  '@odata.context':
   'https://graph.microsoft.com/v1.0/$metadata#subscriptions/$entity',
  id: {...},
  resource: 'users',
  applicationId: {...},
  changeType: 'updated,deleted',
  clientState: {...},
  notificationUrl: 'https://{...}.ngrok.io/api/azure/webhook',
  expirationDateTime: '2020-03-22T11:52:36.328Z',
  creatorId: {...},
  latestSupportedTlsVersion: 'v1_2'
}

However, when I actually go into Azure AD and delete users, I never receive any requests to my endpoint... Any ideas what I'm doing wrong here?

I've seen Not receiving a request on our MS Graph Webhook for deleting a User in AAD, but I've both waited 30 minutes, and tried soft + hard deletes. Neither seems to trigger any sort of request to my endpoint.


Solution

  • Okay, so apparently I was just not being patient enough. It can take hours for MS to send these notification requests.

    If you're developing your webhook endpoint, and looking to test/debug it, do the action in Azure AD, then do something else for a few hours until you finally get the request. 🙄