News/Trends

A Proactive Approach to Tracking Changes on Microsoft 365

Anurag Ranjan, Staff Software Engineer, Vivek Parate, Cloud Apps Engineering Manager and Sourabh Kumar, Cloud Apps Software Engineer

Introduction

The major bottleneck in today’s Microsoft APIs world is throttling, especially for enterprise customers. Throttling is normal, the goal of throttling is to prevent the system from becoming overwhelmed and to maintain stability and performance.

The main challenge with Microsoft’s continuous polling APIs is that you have to monitor your usage closely. Exceeding the APIs’ limit will lead to application performance degradation and additional resource consumption.

Some challenges associated with continuous polling APIs are:

  • Increased network traffic: Continuous polling APIs keep sending requests to Microsoft servers to get change data. This can lead to increased network congestion, slower performance, and unnecessary resources consumption.

  • Increased resource consumption: With continuous polling APIs, server-side resources are continuously processing requests and collecting responses from Microsoft servers, which leads to performance issues. 

  • Increased APIs cost: Microsoft added restrictions on usage limits and quotas designed to prevent excessive use and protect the APIs from overload.

To address the above challenges, Microsoft 365 APIs offer change notifications to provide real-time updates and reduce the need for continuous polling.

Change Notifications - A New Proactive Approach 

Change notification APIs are a useful way for applications to respond to state and data changes. They allow applications to proactively receive notifications when changes have occurred on subscribed resources, rather than having to poll for the latest data. These notifications contain information about the type of change, the resource that was changed, and a token that can be used to retrieve the changed data. Change notifications are often used in conjunction with webhooks, which register the endpoint where the notification will be sent.

How Change Notifications Work

Track changes in M365

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.