Power Platform – Custom Connector to Query M365 Groups Using the Graph API in Pages from Power Automate

Here we will see how to Create, Configure and Consume the Custom Connector to query a M365 group members as a paged result using the M365 Graph api.

Register an Application with a Delegated Group.Read.All permission

First, Register an application for the PowerPlatform Custom connector with the Delegated permission to read the groups.

Create a Custom Connector

Create a new custom connector as below with the host as ‘graph.microsoft.com’

Set the Authentication type

In the Security tab, set the authentication type as below using the details from the registered app.

Update the app with the Custom Connector redirect url

Once the connector is updated, update the app with the redirect url.

Power Platform - Custom Connector to Query M365 Groups using the Graph API in Pages from Power Automate

Create a Definition to get the group members

Create an action to get the list of group members as below.

Power Platform - Custom Connector to Query M365 Groups using the Graph API in Pages from Power Automate

Test the action

Test the configured “getgroupmembers” action.

Amend the action using the Swagger editor to accept the query parameters

Amend the definition to include the additional query parameters required for the graph api to return the list of members for the specified page as below.

Sample swagger json:

paths:
  /v1.0/groups/{id}/members:
    get:
      responses:
        default:
          description: default
          schema: {}
      summary: group
      description: member
      operationId: groupmembers
      parameters:
      - {name: id, in: path, required: true, type: string}
      - name: $top
        in: query
        required : false
        type: array
        collectionFormat: csv
        items: {type: string}
      - name: $skiptoken
        in: query
        required : false
        type: array
        collectionFormat: csv
        items: {type: string}
      - {name: Content-Type, in: header, required: false, type: string}

Test the action with the query parameters

Power Platform - Custom Connector to Query M365 Groups using the Graph API in Pages from Power Automate

Create a Power Automate

We will create a PowerAutomate to read all the group members in pages and call the same action again with the right token to query members of a group.

Add the custom connector action

Include the custom connection action to get group members one at a time as below.

Power Platform - Custom Connector to Query M365 Groups using the Graph API in Pages from Power Automate

Check for the response and call the same action again with the additional parameters

Get the response and check for the @odata.nextLink in the response.

Power Platform - Custom Connector to Query M365 Groups using the Graph API in Pages from Power Automate

Call the same action again by passing the token received from the previous response

Get all the members until the last page of members is received.

Power Platform - Custom Connector to Query M365 Groups using the Graph API in Pages from Power Automate

PowerAutomate Result

Custom Connector

For more great content, check out the Resource Centre

About the Author:

I am an enthusiastic Azure.Net and O365 consultant with a strong commercial awareness. I have carried out several roles as a Lead Developer, Architect and Technical Consultant, in the Health, Telecom and Banking sectors. I am passionate about working with Office 365 / Azure / SharePoint and enjoy attending the SharePoint User Groups as location and time permits.

Reference:

Kailasam, B. (2021). PowerPlatform – Custom Connector to query M365 groups using the graph api in pages from PowerAutomate. Available at: https://clientbala.com/M365-PowerPlatform-CustomConnector-Graph-Paging/ [Accessed: 7th March 2021].

Find more great Power Platform content here.

Share this on...

Rate this Post:

Share: