How to get list of users emails from the SP Group in Power Automate?

Problem

I worked on this on my workflow I want to share, I had few list of SP Groups by the department. e.g. ITApprovers, LegalApprovers, HRApprovers etc. Each SP Group had users in it. For the “Send Approval” action the need was to send approval to these users. I needed semicolon delimited string like following

DebraB@GOV019539.OnMicrosoft.com;JohannaL@GOV019539.OnMicrosoft.com;admin@GOV019539.OnMicrosoft.com

The SP Group ‘HRApprovers’ with three approvers.

Step by Step solution

Step # 1 Define a blank AppoversArray variable.

Initialize the ApproversArray as blank array.

Step # 2 Get all Users email by the SP Group Name

Use the ‘Send and HTTP request to SharePoint’ to get list of user by SP Group. e.g. ‘HRApprovers’
_api/web/SiteGroups/getByName('HRApprovers')/users?$select=Email

Note: In the Uri part you may need to pass the approvers SP Group name using variable. For the simplicity I have hard coded.

The output of the able call will in the following format. We need to get to the “results” from the body to iterate over to get to the ‘Email’.

{
  "d": {
    "results": [
      {
        "__metadata": {
          "id": "https://gov019539.sharepoint.com/sites/test/_api/Web/GetUserById(9)",
          "uri": "https://gov019539.sharepoint.com/sites/test/_api/Web/GetUserById(9)",
          "type": "SP.User"
        },
        "Email": "DebraB@GOV019539.OnMicrosoft.com"
      },
      {
        "__metadata": {
          "id": "https://gov019539.sharepoint.com/sites/test/_api/Web/GetUserById(14)",
          "uri": "https://gov019539.sharepoint.com/sites/test/_api/Web/GetUserById(14)",
          "type": "SP.User"
        },
        "Email": "JohannaL@GOV019539.OnMicrosoft.com"
      },
      {
        "__metadata": {
          "id": "https://gov019539.sharepoint.com/sites/test/_api/Web/GetUserById(12)",
          "uri": "https://gov019539.sharepoint.com/sites/test/_api/Web/GetUserById(12)",
          "type": "SP.User"
        },
        "Email": "admin@GOV019539.OnMicrosoft.com"
      }
    ]
  }
}

Step # 3 Iterate over the results using the Apply Each and append email to the ApproversArray variable.

Iterate over the results array to get the Email. Append the Email to the ApproversArray.

The array of the results is like the following.

outputs('Send_an_HTTP_request_to_SharePoint')?['body']?['d']?['results']

For each item access Email and append to the array

item()?['Email']

Step 4 Join the Aprovers Array with semicolon delimited

Join the ApproversArray with semicolon delimited
join(variables('ApproversArray'),';')

Step 5 Using the above compose from step 4 to send an approval.

The Outputs is the output of the compose variable.

About Pankaj

I am a Developer and my linked profile is https://www.linkedin.com/in/pankajsurti/
This entry was posted in Power Automate. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s