Small Tips and Tricks : Power Platform – Power Automate to add user to specified SharePoint group

Hi All,
Greetings for the day!!!
In last couple of article we are discussing about SharePoint online REST APIs for SharePoint groups / users. Continuing with the series, in this article we will discuss – how to add given user to specific group.
If you miss our last few articles related to groups kindly please have a look
Small Tips and Tricks : Power Platform – Power Automate – simple Power Automate to get all site groups of SharePoint online site – https://knowledge-junction.in/2022/10/11/small-tips-and-tricks-power-platform-power-automate-simple-power-automate-to-get-all-site-groups-of-sharepoint-online-site/
Microsoft 365 : SharePoint Online – Get the Group Membership ID from UI / Fetching all the users of SharePoint group using REST API – https://knowledge-junction.in/2022/10/12/small-tips-and-tricks-power-platform-power-automate-simple-power-automate-to-get-site-group-id-from-group-display-name/
Small Tips and Tricks : Power Platform – Power Automate – simple Power Automate to get site group Id from group display name – https://knowledge-junction.in/2022/10/12/small-tips-and-tricks-power-platform-power-automate-simple-power-automate-to-get-site-group-id-from-group-display-name/
Frequently used REST APIs – Part 1 – https://knowledge-junction.in/2022/09/01/frequently-used-rest-apis-part-1/
High level steps
- From group display name get the group id – GET REST API – _api/web/siteGroups/getByName(‘<GROUP DISPLAY NAME>’) OR _api/web/sitegroups?$filter=LoginName eq ‘<GROUP DISPLAY NAME>’&$select=Id&top=1
- Call the POST REST API to add user to the given specified group – _api/web/sitegroups(GroupID)/users we need to specify the log in name of user in JSON format in body of “Send an HTTP request to SharePoint” action
Power Automate
- Create “Instant Cloud flow” so that we could test manually
- Add the Manual trigger action

- Next step is to fetch the GroupId in which we need to add the respective user
- We have very good article on fetching GroupID, please have a look – Small Tips and Tricks : Power Platform – Power Automate – simple Power Automate to get site group Id from group display name
- Add an “HTTP” action – “Send an HTTP request to SharePoint” to fetch the GroupId as

- Lets use “Compose” action to see the result as
- Initialize the variable “GroupId” to store GroupId so that we can use it in our next action to add the user
- Action – Initialize variable
- Next step is to put the “POST” request to add given user to above given group
- We will use above “GroupId” variable
- We have REST API – _api/web/sitegroups(‘GroupID’)/users and in body of action “Send an HTTP request to SharePoint” we will specify user claim as as
{
"__metadata":{"type":'SP.User'},
'LoginName':'i:0#.f|membership|prasham@knowledgejunction1.onmicrosoft.com'
}
Complete Power Automate

References
- Frequently used REST APIs – Part 1 – https://knowledge-junction.in/2022/09/01/frequently-used-rest-apis-part-1/
- Power Platform : Power Automate – calling SharePoint REST API – https://knowledge-junction.in/2022/07/12/power-platform-power-automate-calling-sharepoint-rest-api/
- Small Tips and Tricks : Power Platform – Power Automate – simple Power Automate to get site group Id from group display name – https://knowledge-junction.in/2022/10/12/small-tips-and-tricks-power-platform-power-automate-simple-power-automate-to-get-site-group-id-from-group-display-name/
Thanks for reading !! If its worth at least reading once, kindly please like and share !!! SHARING IS CARING 🙂
Enjoy the beautiful life !! Have a FUN !! HAVE A SAFE LIFE !! TAKE CARE 🙂
You must be logged in to post a comment.