How to receive lifecycle notifications for event subscriptions

David Gentles 10 Reputation points
2023-10-02T15:36:22.91+00:00

I am using the graph API to receive change notifications for events. I am able to successfully receive notifications when an event is created, updated or removed.

I have also set up the subscription with a separate url with which to send lifecycle notifications. Validation of the lifecycle notification url is being performed correctly- returning anything other than a 200 results in the subscription not being created.

But- I never actually receive a lifecycle notification beyond that. I have set up subscriptions with expiry dates 15 minutes, 1 hour and 2 hours in the future, and I receive nothing as they approach expiry or when they expire. Changing the password of the subscribed user also does not result in a lifecycle notification.

I have been following this documentation:

https://learn.microsoft.com/en-us/graph/webhooks-lifecycle
https://learn.microsoft.com/en-us/graph/change-notifications-delivery-webhooks?tabs=http#notificationurl-validation

https://learn.microsoft.com/en-us/graph/api/subscription-post-subscriptions?view=graph-rest-1.0&tabs=http

A very rough demonstration of what I'm calling to create a subscription:

expiration_time = datetime.now(timezone.utc) + timedelta(minutes=120)

setup_json = {
    "changeType": "created, updated, deleted",
    "notificationUrl": notification_url,
    "lifecycleNotificationUrl": lifecycle_notification_url,
    "resource": "me/events",
    "expirationDateTime": expiration_time.isoformat(),
    "clientState": SOME_CLIENT_STATE,
}

setup_result = requests.post(
    "https://graph.microsoft.com/v1.0/subscriptions",
    json=setup_json,
    headers={"Authorization": f"Bearer {access_token}"},
)

Have other developers been able to successfully receive lifecycle notifications? Is there anything above that appears wrong? Any help would be appreciated!

Microsoft Security Microsoft Graph
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. David Gentles 10 Reputation points
    2023-10-03T10:08:06.1566667+00:00

    Turns out patience was key- I was able to see a reauthorizationRequired notification returned from a subscription with an expiry time 1 hour into the future. The lifecycle notification came through about one minute before the subscription expired.

    I still have not been able to receive a lifecycle notification when the user changes their password though.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.