How to Create SharePoint Group using Power Automate?

In this Power Automate tutorial, we will see how to create a SharePoint group using Power Automate. Also, we will see how we can add users to the SharePoint group. Furthermore, we will allocate permission to the SharePoint group using Power Automate.

SharePoint Group is a feature in Microsoft SharePoint, which allows us to manage permission and control access to SharePoint sites, lists, libraries, and other content. Basically, it is a group of users who are brought together for the purpose of improving permission control and collaborating in a SharePoint environment.

I have a SharePoint list called ‘SharePoint Groups’, which contains the below columns:

  • Group Name (Title) -Single line of Text
  • Members: Person
  • Description: Multiple line of text
  • Group Permission: Choice
create group using Power automate
SharePoint Online List

When a user will create an item in the above list, the flow will trigger. Based on the Group name it will first create a SharePoint group, then it will add members to it (From the Members Column in the above list) and assign permission to the SharePoint group using Power Automate.

How to create SharePoint Group using Power Automate

Here we will see how a user can create a group by providing information related to SharePoint group using Power Automate.

Before we start the flow creation, just set up the SharePoint list i.e. SharePoint Group’ by adding the above columns.

Let’s follow the below steps to create the Automated cloud flow, which will perform the below tasks:

  • Create SharePoint Group
  • Add members to it
  • Provide Permission to the SharePoint group

Create SharePoint Group using Power Automate

Here we will see how to create a SharePoint group automatically in the SharePoint site using Power Automate.

See also  Power Automate delete emails older than [15 days example]

Before creating the flow in Power Automate, just set up the SharePoint list ‘SharePoint group’ with the above columns.

Step 1: Log in to Power Automate, click on the +Create icon -> select the Automated Cloud Flow.

How to create SharePoint group using Power automate


Then provide the flow name, and select When an item is created action. Click on Create.

Create SharePoint group using Power automate

Now you can see When an item is created action is added to the flow. You can provide the below information:

  • Site address: Select or provide the SharePoint site address
  • List name: Select or Provide the list name
Create SharePoint group using Microsoft Power automate

Step 2: We will create the site content type, so click on the +New step button -> select the ‘Send an HTTP request to SharePoint‘ action. Then provide the below information:

  • Site address: Select or provide the SharePoint site address.
  • Method: Select the method POST as we are creating the SharePoint Group in SharePoint Online
  • Uri: Provide the below code as Uri:
/_api/Web/SiteGroups
  • Headers: Provide the code as a header, it requires for API call:
{
  "content-type": "application/json;odata=verbose"
}
  • Body:  Provide the body as the below code, which contains information related to the SharePoint group.
{
    "__metadata": {
        "type": "SP.Group"
    },
    "Title": "@{triggerOutputs()?['body/Title']}",
    "Description": "@{triggerOutputs()?['body/Description']}"
}
How to create SharePoint group using Microsoft Power automate

Add members to the SharePoint group using Power Automate

Step 3: To add members to the SharePoint group, we need the group id. So, click on the +New step button -> select the Compose action. Then provide the below information:

  • Inputs: Provide the below code:
@{body('Send_an_HTTP_request_to_SharePoint')['d']['Id']}
How to create SharePoint group in SharePoint site using Microsoft Power automate

Step 4: We will create the add users to the SharePoint group, so click on the +New step button -> select the ‘Send an HTTP request to SharePoint‘ action. Then provide the below information:

  • Site address: Select or provide the SharePoint site address.
  • Method: Select the method POST as we are adding members to the SharePoint Group in SharePoint Online
  • Uri: Provide the below code as Uri:
_api/web/sitegroups(@{outputs('Compose_-group_id')})/users
  • Headers: Provide the code as a header, it requires for API call:
{
  "Accept": "application/json;odata=verbose",
  "Content-Type": "application/json;odata=verbose"
}
  • Body:  Provide the body as the below code, which contains information related to the users. In the body when you select the LoginName value from the dynamic content, it will automatically add Apply to each action.
{
  "__metadata": {
    "type": "SP.User"
  },
  "LoginName": "@{triggerOutputs()?['body/Members/Claims']}"
}
Create SharePoint group in SharePoint site using Microsoft Power automate

Provide permission to a SharePoint group using Power Automate

Step 5: To assign the permission, first we need the Role Definition Id, so click on the +New Step -> select ‘Send an HTTP request to SharePoint’. Then provide the below information:

  • Site address: Select or provide the SharePoint site address.
  • Method: Select the method GET as we are getting the Role Definition Id.
  • Uri: Provide the below code as Uri:
_api/web/roleDefinitions/getByName('@{triggerOutputs()?['body/GroupPermission/Value']}')
How to create SharePoint group using Microsoft flow

Step 6: Next, click on the +new step -> select the Compose action. Then provide the below information:

  • Inputs: Provide the below expression:
@{body('Send_an_HTTP_request_to_SharePoint_3')?['d']?['Id']}
How to create SharePoint group using flow

Step 7: Now assign permission to the SharePoint group, so click on the +New step -> select the ‘Send an HTTP request to SharePoint‘ action. Then provide the below information:

  • Site address: Select or provide the SharePoint site address.
  • Method: Select the method POST as we are assigning permission to the SharePoint Group in SharePoint Online
  • Uri: Provide the below code as Uri:
/_api/web/roleassignments/addroleassignment(principalid=@{outputs('Compose_-group_id')}, roleDefId=@{outputs('Compose-role_id_')})
  • Headers: Provide the code as a header, it requires for API call:
{
  "content-type": "application/json;odata=verbose"
}
create SharePoint group using flow

Step 8: Now click on Save, then click on the Test icon -> select Manually -> click on Test button -> configure the connectors, click on Run flow -> click on Done.

See also  Power Automate Parallel Branch with Examples

Next create an item in the SharePoint list to trigger the flow, in Power Automate.

Create SharePoint group using Microsoft flow


Now, to check the group is created, click on the setting⚙️icon -> click on Site permission -> select Advance Permission Setting.

Here you can see your Group, once you will click on the group -> see the members you have added. To check that Permission is assigned properly or not, click on the Setting icon -> select View Group Permission.

As I have created a Developer Team group and added the below 2 members and provide read permission to this group, you can see in the below screen-shot

create SharePoint group using MS flow
create a SharePoint group using MS flow

This is how we can create a SharePoint group, add members, and assign SharePoint Permission to it using Power Automate.

Conclusion

In this Power Automate tutorial, we saw how to create a SharePoint group using Flow or Power Automate. Also, we saw how to add members and assign permission to the SharePoint group using Power Automate.

You may also like:

>