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.
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.
Img2. Created instant cloud flow
Step 3
Now we need to trigger an action. I have selected when an item is created or modified.
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.
Img4. Updated site and list details.
Step 5
Now choose an action. We need to send an http request to SharePoint.
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.
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
Img7: update action menu
Update body address bar with {"__metadata":{"type":"SP.User"},"LoginName":"CompletedByclaims"}.just dynamically choose CompletedByclaims.
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.
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.
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!
Img11. User added correctly after flow runs