cancel
Showing results for 
Search instead for 
Did you mean: 
sergeluca

Extend Microsoft Flow with the Microsoft Graph ...and 0 code !

3 weeks ago I was involved in a project combining Office 365, SharePoint Online and Microsoft Flow. One of the problem I had to solve was that I needed to store the list of Office 365 groups in a SharePoint list.

 

If you check Microsoft Flow there is no action for doing this, the Office 365 groups action sare the following:

 

nolistofgroups

 

One solution was to create a custom connector, like an Azure function as I illustrated before, but I wanted something lighter.

So what I did was to use the Microsoft Graph, which will become the standard way of interacting with Microsoft cloud products.

And retrieving the list of group with the Microsoft Graph is something very easy:

 

https://graph.microsoft.com/v1.0/groups?$orderby=displayName

 

That's it. You will get a JSON response that looks like this:

 

{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#groups","value":[

{"id":"3d017548-4545-4050-a659-661126236618","deletedDateTime":null,"classification":null,"createdDateTime":"2016-10-24T18:10:32Z","description":"AOS Bxl 2016 Flow","displayName":"AOS Bxl 2016 Flow","groupTypes":["Unified"],"mail":"aosbxl2016flow@contoso.com","mailEnabled":true,"mailNickname":"aosbxl2016flow","onPremisesLastSyncDateTime":null,"onPremisesProvisioningErrors":[],"onPremisesSecurityIdentifier":null,"onPremisesSyncEnabled":null,"proxyAddresses":["smtp:aosbxl2016flow@ShareQL.onmicrosoft.com","SMTP:aosbxl2016flow@ShareQL.com"],"renewedDateTime":"2016-10-24T18:10:32Z","securityEnabled":false,"visibility":"Public"},

{"id":"b8aa1cc1-97a1-478e-97a5-51ab2dba857e","deletedDateTime":null,"classification":null,"createdDateTime":"2017-04-04T13:36:40Z","description":"Azure Data Factory","displayName":"Azure Data Factory","groupTypes":["Unified"],"mail":"AzureDataFactory@contoso.com","mailEnabled":true,"mailNickname":"AzureDataFactory","onPremisesLastSyncDateTime":null,"onPremisesProvisioningErrors":[],"onPremisesSecurityIdentifier":null,"onPremisesSyncEnabled":null,"proxyAddresses":["smtp:AzureDataFactory@ShareQL.onmicrosoft.com","SMTP:AzureDataFactory@ShareQL.com"],"renewedDateTime":"2017-04-04T13:36:40Z","securityEnabled":false,"visibility":"Private"}

]}

 

OAuth 2.0 is an authorization protocol. It defines how your app can get access tokens by authenticating directly with Azure AD.

In order to use the Microsoft Graph, we need to define an Azure App that will be authorized via OAuth 2.0 by  (first) authenticating directly with Azure AD.

So we will need a clientid and a secretid.

Some permissions are of course required for the Microsoft graph in the App definition.

 

  • graphpermissions

 

Don't forget to define your secretid.

When this has been set up, we can create our Flow (I will just present a simplified version of my flow that we can start by pressing a button 🙂

Now any call to the Microsoft Graph requires an access token; to get it you need to provide your application client, secret id and tenant id.

 

Define 3 variables in your Flow (see picture below)

 

Client Id, Secret Id, Tenant Id and store the corresponding values. Here is how you can  find your tenant id.

 

tenantid

 

To generate the access token, we can use the out of the box Http action and pass the required parameters to the https://login.microsoftinline.com/<tenantid>/oauth2/token url :

 

generate access token

 

When we run the workflow we clearly see the access token in the output of the Generate Access Token action :

generate the schema

 

We need to be able to parse this value in order to pass it to our Microsoft graph calls.

To achieve this we can use a JSON parser variable, but first we need to understand the schema. Let's copy the body information above and past it in a Parser JSON variable as an example to generate the schema :

generate the schema2

 

...and voilà, a schema will be generated :

generate the schema3

 

The Content of the action must be set to the Body of  the action Generate Access Token.

 

Next we are ready to call the Microsoft graph with an Http action ("GetTenantGroups") :

callGraph

 

The next step is to parse the Microsoft Graph response and to  store the information in a SharePoint list.

 

Here again we need to use the JSON parse action, but for this we need to define a schema by generating an example from the Graph explorer :

graphexplorer

 

If you copy & paste these value in the JSON Parser action schema generator, you will get some errors at runtime : I've used the online JSon validator to validate the schema generated by the Flow JSON Parser action. Some values like description and a few others were null; so I've updated their settings as any in the schema.

Here is my schema :

{
"type": "object",
"properties": {
"@@odata.context": {
"type": "string"
},
"value": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"deletedDateTime": {
"type": "any"
},
"classification": {
"type": "any"
},
"createdDateTime": {
"type": "string"
},
"description": {
"type": "any"
},
"displayName": {
"type": "string"
},
"groupTypes": {
"type": "array",
"items": {
"type": "string"
}
},
"mail": {
"type": "string"
},
"mailEnabled": {
"type": "boolean"
},
"mailNickname": {
"type": "string"
},
"onPremisesLastSyncDateTime": {
"type": "any"
},
"onPremisesProvisioningErrors": {
"type": "array"
},
"onPremisesSecurityIdentifier": {
"type": "any"
},
"onPremisesSyncEnabled": {
"type": "any"
},
"proxyAddresses": {
"type": "array",
"items": {
"type": "string"
}
},
"renewedDateTime": {
"type": "string"
},
"securityEnabled": {
"type": "boolean"
},
"visibility": {
"type": "any"
}
},
"required": [
"id"
]
}
}
}
}

 

We are now ready to store the group info into a SharePoint list by using the Apply to each action :

 

storegroupsinsplist

 

 

The whole Flow looks like this :

 

wholegroupflow

 

Comments
About the Author
  • Experienced Consultant with a demonstrated history of working in the information technology and services industry. Skilled in Office 365, Azure, SharePoint Online, PowerShell, Nintex, K2, SharePoint Designer workflow automation, PowerApps, Microsoft Flow, PowerShell, Active Directory, Operating Systems, Networking, and JavaScript. Strong consulting professional with a Bachelor of Engineering (B.E.) focused in Information Technology from Mumbai University.
  • I am a Microsoft Business Applications MVP and a Senior Manager at EY. I am a technology enthusiast and problem solver. I work/speak/blog/Vlog on Microsoft technology, including Office 365, Power Apps, Power Automate, SharePoint, and Teams Etc. I am helping global clients on Power Platform adoption and empowering them with Power Platform possibilities, capabilities, and easiness. I am a leader of the Houston Power Platform User Group and Power Automate community superuser. I love traveling , exploring new places, and meeting people from different cultures.
  • Read more about me and my achievements at: https://ganeshsanapblogs.wordpress.com/about MCT | SharePoint, Microsoft 365 and Power Platform Consultant | Contributor on SharePoint StackExchange, MSFT Techcommunity
  • Encodian Owner / Founder - Ex Microsoft Consulting Services - Architect / Developer - 20 years in SharePoint - PowerPlatform Fan
  • Founder of SKILLFUL SARDINE, a company focused on productivity and the Power Platform. You can find me on LinkedIn: https://linkedin.com/in/manueltgomes and twitter http://twitter.com/manueltgomes. I also write at https://www.manueltgomes.com, so if you want some Power Automate, SharePoint or Power Apps content I'm your guy 🙂
  • I am the Owner/Principal Architect at Don't Pa..Panic Consulting. I've been working in the information technology industry for over 30 years, and have played key roles in several enterprise SharePoint architectural design review, Intranet deployment, application development, and migration projects. I've been a Microsoft Most Valuable Professional (MVP) 15 consecutive years and am also a Microsoft Certified SharePoint Masters (MCSM) since 2013.
  • Big fan of Power Platform technologies and implemented many solutions.
  • Passionate #Programmer #SharePoint #SPFx #M365 #Power Platform| Microsoft MVP | SharePoint StackOverflow, Github, PnP contributor
  • Web site – https://kamdaryash.wordpress.com Youtube channel - https://www.youtube.com/channel/UCM149rFkLNgerSvgDVeYTZQ/