Application Registration
To use change notification APIs, applications must register with Microsoft 365’s API services. The application provides information such as its name, endpoint URL, and the resources it wants to capture.
Subscription
Users set up the subscription and determine how they want to be notified if resources change in the Microsoft 365 account.
Notification Delivery
When a change occurs to a monitored resource, Microsoft 365 sends a notification to the specified endpoint URL for the application. The notification contains details about the change, such as the type of change, the resource that was changed, and a token that can be used to retrieve the changed data.
Data Retrieval
After receiving a change notification, the application can use the included token to retrieve the changed data from the Microsoft 365 API service. The application can then process the data and take appropriate actions based on the changes.
Subscription Management
Applications can manage their subscriptions by creating, updating, or deleting them as needed. Subscriptions can also be automatically deleted if they expire or are no longer needed.
Sample Code
Sample Code for Microsoft Group - Change Notification
|
import requests
import json
#Application registration details
client_id = '<your-client-id>'
client_secret = '<your-client-secret>'
tenant_id = '<your-tenant-id>'
resource = 'https://graph.microsoft.com/'
subscription_url = 'https://graph.microsoft.com/v1.0/subscriptions'
#Authentication
authority_url = 'https://login.microsoftonline.com/' + tenant_id
auth_url = authority_url + '/oauth2/token'
payload = {
'grant_type': 'client_credentials',
'client_id': client_id,
'client_secret': client_secret,
'resource': resource
}
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
response = requests.post(auth_url, headers=headers, data=payload)
access_token = response.json()['access_token']
#Create subscription
subscription_data = {
'changeType': 'updated',
'notificationUrl': '<your-notification-url>',
'resource': '/groups/<group-id>',
'expirationDateTime': '2022-02-01T00:00:00Z'
}
headers = {
'Authorization': 'Bearer ' + access_token,
'Content-Type': 'application/json'
}
response = requests.post(subscription_url, headers=headers, json=subscription_data)
subscription = response.json()
#Print subscription ID
print('Subscription ID:', subscription['id'])
|
Benefits of Change Notification
The benefits of using change notification APIs include:
Real-time Updates
Change Notification APIs enable applications to receive real-time data updates when changes occur in Microsoft services. With change notification APIs, applications can respond to changes immediately, a comprehensive solution to traditional challenges with continuous polling.
Reduced Network Traffic
Polling APIs can generate a lot of network traffic, especially when polling frequently. Change notification APIs reduce network traffic because they only send notifications when changes occur, rather than having to poll for changes continuously.
More Efficient Resource Usage
Change notification APIs remove continuous polling to help applications use resources more effectively and avoid waste.
Change notification APIs provide significant benefits for applications that need real-time data for particular actions or need to respond quickly.
Summary
Change notification APis are a new way for redesigning your application. It helps to enable real-time data capture for subscribed resources when changes take place. Change notification APIs help reduce unnecessary API calls to Microsoft and help reduce throttling issues, network traffic, and more.
Next Steps
Explore Druva’s industry-leading, 100% SaaS-based data protection for Microsoft 365 on the Druva site. And visit the tech/engineering section of the blog archive for a closer look at the innovations driving Druva’s continued data protection success.