Add A User To A SharePoint Group

Introduction 

 
In this blog, we will see how to add a user to a SharePoint group when an item is created or modified using Power Automate or Microsoft Flow. We need to follow the below steps to add a user to a SharePoint group.
 
Step 1
 
I have created a custom list with a user field. When I update an item with a user value, that particular user will be added to our group.
 
Add User To A SharePoint Group
Img1. This is my custom list. Here Completed By is my person/group field.
 
Step 2
 
Now we need to create our Microsoft Flow. Log in to Microsoft Office 365 portals. From the app launcher menu, click on flow to create a Microsoft Flow.
 
Add User To A SharePoint Group
Img2. Created instant cloud flow
 
Step 3
 
Now we need to trigger an action. I have selected when an item is created or modified.
 
Add User To A SharePoint Group
Img3. Skip limited trigger action and choose when an item is created or modified menu in advance option
 
Step 4
 
Give a site address and list name on the address bar. Click on next step.
 
Add User To A SharePoint Group
Img4. Updated site and list details.
 
Step 5
 
Now choose an action. We need to send an http request to SharePoint.
 
Add User To A SharePoint Group
Img5. Choose action
 
Step 6
 
Update site address, method, URI, and header values. Here we will add the “Post” method as we will write user to the group. My Uri value is “_api/web/sitegroups(4)/users”. Here, 4 is my group id.
 
Add User To A SharePoint Group
Img6. This is the group where we will add a user
 
Add a header and content as given below:
 
Accept application/json;odata=verbose
Content-type application/json;odata=verbose
 
Add User To A SharePoint Group
Img7: update action menu
 
Update body address bar with {"__metadata":{"type":"SP.User"},"LoginName":"CompletedByclaims"}.just dynamically choose CompletedByclaims.
 
Add User To A SharePoint Group
Img8: action menu body address bar update
 
Step 7
 
Save the flow with a proper name. Now we need to add an item to our list.
 
Add User To A SharePoint Group 
Img9. Added item to a custom list.
 
Step 8
 
Now go to “My flows” to check whether the flow is successful or not. Refresh the browser in few seconds and it will show the build status.
 
Add User To A SharePoint Group
Img10. Flow run succeeds
 
Step 9
 
Now to go to the SharePoint group to check the result. The user is added to the group successfully!
 
Add User To A SharePoint Group 
Img11. User added correctly after flow runs