Microsoft Graph Delta Query from Microsoft Flow: Part 1
Have you ever wanted to create a Flow that could monitor something in Office 365 (like a group) and do something if that thing changed? Well, that is what Delta Queries are for. The word “Delta” will refer here to the difference, or change, in a certain quantity - not to the outflow of a river! The Microsoft Graph supports Delta Queries on certain objects, like Azure AD Security Groups. The concept is pretty easy to understand and is very well documented. The pattern is:
state token
. The token is either:
nextLink
indicating that there are additional pages of datadeltaLink
indicating that there is no more data and the next request should use the deltaLink
to determine changes in the resource.deltaLink
and return to step 2.There are other nuances as some Azure AD objects support advanced sync features, but for our scenario we will follow this pattern.
In researching this process, I found several very good resources for using the Microsoft Graph with Microsoft Flow. My favorite resource is my great friend Serge Luca, MVP @SergeLuca, he has presented and written a great deal about using Flow. You can find him in the Microsoft Flow Community where he shares advice and regularly publishes helpful articles. Serge helped me to understand how to call the Microsoft Graph. After researching with people like Serge and after reading a mind-numbing number of articles, I created this “basic”” post to save my readers time. Many of the posts in the Flow Community were written before the basics, like how to create your app through https://apps.dev.microsoft.com/, had changed.
So, here we go. In this three-part series we are going create a Flow that monitors an Azure AD Group and then does stuff based on what changed. The goal is to demonstrate the pattern for the Delta Query. I am just going to maintain a SharePoint list, but you can do anything you like with the information. For example, you could send each member in the group a “welcome email” or use the membership in a group to assign licenses to users in a third party app like Spanning Backup for Office 365!
Part 1: The App, Consent, and the Plan (this post)
Before you dive into Flow, you need to prepare a few things in order for Flow to make a request of the Microsoft Graph. Permissions can be tricky, so be sure that you are logged into the Azure Portal https://portal.azure.com with an account that can grant rights to the resources you want to access. In my case I am logged in with a Global Administrator account.
These are the basic prerequisites:
In order to use the Graph from Flow you have to create an “App” with the appropriate consent that Flow will use to gain access to the items of interest in the graph. This is easy enough (no development skills required) this process is in Preview right now, so if my screenshots are a little off please let me know.
Congratulations! You created an App, and you told the app what things it was going to access in the Graph API. Now you need to Consent to those permissions. Ordinarily you would do this while installing the App. In our case we’re going to “fake it” by sending all of the necessary info like the App ID and Tenant ID along to Azure.
https://login.microsoftonline.com/{Tenant ID}/adminconsent?client_id={App ID}&redirect_uri={Home Page}
https://login.microsoftonline.com/ec4a76a0-9603-4584-994e-9f0bd62c674a/adminconsent?client_id=4dff8542-c730-4a85-99be-8da4752cac38&redirect_uri=https://localhost/flowdeltaquery
After I’ve completed the prerequisites, I find it saves a lot of time if I draw out my workflow plans before diving into Flow. I’ve used Visio - you might use other tools. Below is my Visio drawing that represents the Flow that I plan to create. There are essentially three phases to what I am building:
Note that between executions of the flow I will need to store the deltaLink
somewhere and then retrieve it on the subsequent execution. I plan to do that in SharePoint, but you could use any service you like since it is just a long string of text.
In my SharePoint online tenant I created a site collection for storing the results from our delta query. On that site create two lists:
OK, now you have the basis for the next two posts all set up. In the next post we’ll perform our initial query and store the Delta Link. In the final post we’ll retrieve the Delta Link and submit a Delta Query.
Ready to start your next project with us? That’s great! Give us a call or send us an email and we will get back to you as soon as possible!
+1.512.539.0322