How to add users to SharePoint group using Flow
In this article we will see how to add users to SharePoint group using Microsoft Flow or Microsoft Power Automate.
Let's start by having a look on the rest api to add users to SharePoint group
Rest api to add users to SharePoint group
Rest end point to add users into SharePoint group is given below
So to add users to group we need to make POST request to this endpoint and of course we need to pass user as metadata as below
Now to we know the main task, lets start creating the flow.
Create a mannually triggered Flow
In order to create a mannually triggered flow, follow below steps.
Go to https://flow.microsoft.com
Click on My flows in left section
Click new top and select Instant - from blank
Choose mannually triggred flow and click Create
At this time your flow will be created. Now lets say we know the group name and then we need to have group id in order to add user to that group
Get Group Id by Group name
Add a new step and select "Send an HTTP request to SharePoint"
1. Enter your site address
2. Choose method as GET
3. In URI inter below
_api/web/SiteGroups?$filter=LoginName eq 'group name'&$select=Id&$top=1
Replace group name with your group here and add two headers as below
accept : application/json;odata=verbose
content-type : application/json;odata=verbose
we will need to parse the response to get group Id. run the the flow once and from run history copy the response body of above activity.
Getting Group Id
To get group id, We can parse the body of reponse of request we send to get the group above. but to parse the response we need to have schema and luckly we have a way to get schema.
Just run the flow once and then go to run history and click on send request to SharePoint step and it will be expanded and then copy the json body of the response and have it some where.
Now return back to flow, and add a new step and choose parse json.
In body select body from send an HTTP request to SharePoint and in schema
Click generate from sample and paste the json copied in previous step and you are done.
Add users to SharePoint group
Now we know the group id and we need to add users to SharePoint group. Lets add a new step "Send an HTTP request to SharePoint" and choose below
In Site address, enter your site address
Choose POST method
In URI enter below
notice that your activity will be enclosed with apply to each step loop.This is because result obtained from parse Json step is collection.
_api/web/sitegroups("select id from above parse json step")/users
Add two headers accept and content-type the value of both will be application/json;odata=verbose
Enter metadata as below
add your user name to add on the place of abc and you are done. test the flow by mannually triggering and see the result
Would you like to see your article here on tutorialsinhand.
program by tutorialsinhand.com
About the Author
Always ready to learn new technologies, A problem solver, exhibit to do attitude. Having around 10+ years of experience of development and management skills. I believe don't just set random goals but right goals suited for you.
Page Views :
Published Date :