Office 365 Groups Management As A Service: Episode II: Know your groups with Flow, MSGraph
/This is the second post on building a group management tool with Flow and MSGraph. In this post we talk about how to get a list of all your groups and copy them to a list in SharePoint so you can do more fancy things with them.
Plan
- Call MSGraph with Flow to get a list of all your Office 365 Groups
- Create a SharePoint list to store them
- Create/Update SharePoint list items
(these steps above are good enough, the steps below are bonus points)
- Delta Query
- More Details
- Parallel Execution
- [NEW] Paging (if you have more than 100 groups) - suggestion to this post by @mikaelsvenson
MSGraph to List Groups
Some of you may have seem my love letter tweet.
- MS Graph endpoint is https://graph.microsoft.com/v1.0/groups - docs
- Authority is https://login.microsoftonline.com/
- Audience is Resource: https://graph.microsoft.com
- Tenant ID, Client ID and Client Secret you'll need to register an App-Only credential app to get these. Grant that App permission to Read Groups
Create a SharePoint List to store them
Complete the Flow to store Groups to SharePoint
This picture is complex, because it has a lot of tricky parts that's mostly caused by the way Flow's Editor works. Flow's editor will try to filter the variables available to you by type, the Parse JSON action will parse JSON into a strongly type object following a strict schema. This lets your subsequent actions work well.
BUT when your action returns null then suddenly the Parse JSON action can fail. You'll then need to go back to the schema, and change some of the error "types" to "any". You also may need to remove some of the fields from "required"
A few tweaks to the Parse JSON:
These tweaks are necessary because Parse JSON will fail if one of your groups don't have a createDateTime, classification or displayName. You need to run this on your environment and check whether the fields need to be required or tweaked.
Paging
Delta Query
Because MS Graph supports Delta Queries - we can call the Graph with a Delta Query link, essentially, each time we call it, it'll return a nextLink (or a deltaLink). So we just remember that, and use it the next time we want to call MS Graph again, and it will tell us just the differences.
See the delta query picked up one new Group I created for testing.
With a delta query - you can reliably set the Flow to run several times a day, and it will only send new/updated Groups back into the SharePoint list.
More Group Details
Sometimes you want more information on that group. You can call Get group (on Azure AD connector) to get more information on the group.
Parallel
We can configure the foreach action in Flow to run in parallel with 20 concurrency. You'll need to add this to the definition JSON.
See the task of writing 19 Office 365 groups to sharepoint list was done in 4 seconds.
Result
[New] Paging
This section is added as @mikaelsvenson pointed out that I wasn't handling paging for groups. Mikael also told me to use $top so I don't have to create a few hundred groups for testing.
Always listen to Mikael.
But I don't want to do loops - I've seen a pagination control, I want to know what that does.
Go to the settings for HTTP action and the first one is Pagination.
Turn that on, and set the limit to 5000.
- Pagination controls seems to merge the results of multiple requests into one value array. This is good.
- Pagination controls works on Delta query - this is also good.
- Pagination results does not return the deltaLink for next Delta query. This is not so good. So if we are planning to merge both Pagination and Delta Query we'll need to may be make two calls.
Notes
- Use HTTP with Azure AD Auth to get all my groups in one call
- Save that to SharePoint
- Deal with Delta Queries with Flow
- Configure Parallel execution in Flow so we can do this super fast. This isn't code that runs one group at a time... why would we do that when we can hit 20 at a time :-)