Articles

How to add users to SharePoint group using Flow

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

_api/web/sitegroups()/users

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

{"__metadata":{"type":"SP.User"},"LoginName":"abc"}  

 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.

  1. Go to https://flow.microsoft.com

  2. Click on My flows in left section

  3. Click new top and select Instant - from blank

  4. 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"

Enter your site address 

Choose method as GET

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

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

  1. In Site address, enter your site address
  2. Choose POST method
  3. In URI enter below                                                                                                                  
    _api/web/sitegroups(

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com
Page Views : 139    Published Date :Apr 19,2020   Author :Mukesh Tiwari
Please Share this page

Popular Articles

Loading...
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!