Sep 22 2022 04:42 AM
Hi,
I am trying to find a solution to Add a security group as a member of a teamsite by flow.
When i create a new site i want to automatically ad a security group.
Tried to find something with 'send to HTTP' uri but can't find anything... anyone have an idea to solve this?
Sep 22 2022 04:48 AM
@HoSFonnan You can use HTTP request action and REST API to add user to SharePoint group. Follow below links for more information:
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
Sep 22 2022 04:50 AM
Sep 22 2022 04:58 AM
@HoSFonnan Do you want to add security group inside a SharePoint group OR add security group directly under site permissions?
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
Sep 22 2022 04:59 AM
Sep 22 2022 06:47 AM
@HoSFonnan Use flow like this:
This grant contribute access to security groups. You can find other roledefid values in my answer at: SP REST - add an existing group to site with REST API?
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
Sep 26 2022 04:08 AM
@ganeshsanap Hi,
But i cant add an existing domain/security group with this flow?
I want to add this group automatic when you create a new site.
After I test run your example flow i get this result:
Sep 26 2022 04:22 AM
@HoSFonnan If your security group is added to the site previously at least once, you can also ignore first action in above flow OR you can use it always for safer side in case group is not added previously.
Check if you are using correct group name in flow actions. Can you add a screenshot of your flow to investigate further?
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
Sep 26 2022 04:51 AM - edited Sep 26 2022 04:51 AM
Sep 26 2022 05:31 AM
@HoSFonnan Use $filter instead of $filer in HTTP request action.
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
Sep 26 2022 05:36 AM
@HoSFonnan Here are the Uri I used for your reference (first HTTP action to get user information):
_api/web/siteusers?$select=Id,Title&$filter=Title eq 'Security-Group-01'
In Compose action, use expression like:
body('Send_an_HTTP_request_to_SharePoint_2')?['d']?['results']?[0]?['Id']
Uri in HTTP - Grant permission action:
_api/web/roleassignments/addroleassignment(principalid=@{outputs('Compose')}, roledefid=1073741827)
Where @{outputs('Compose')} is the dynamic expression from compose action.
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
Sep 26 2022 05:43 AM
Sep 26 2022 06:07 AM
Solution@HoSFonnan To add security group to new SharePoint site, you first need to use the ensureUser endpoint which checks whether the specified login name (security group) belongs to a valid security group in the site. If the security group doesn't exist, adds the security group to the site.
Check first HTTP action given in my initial response. Provide display name of group to logonName property.
Then you can use the _api/web/siteusers endpoint to get security group Id from SharePoint user information list which you will use to grant permissions on site.
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
Sep 26 2022 07:24 AM
Sep 27 2022 01:36 AM
Sep 27 2022 01:52 AM
@HoSFonnan Yes, you can grant permissions to folder as well after you get the security group ID from SharePoint.
Starting Uri for folder permissions will be something like this:
_api/web/getFolderByServerRelativeUrl('/sites/dev/doc1/Folder1')/ListItemAllFields/RoleAssignments
Please consider giving a Like if my post helped you in any way.
Sep 26 2022 06:07 AM
Solution@HoSFonnan To add security group to new SharePoint site, you first need to use the ensureUser endpoint which checks whether the specified login name (security group) belongs to a valid security group in the site. If the security group doesn't exist, adds the security group to the site.
Check first HTTP action given in my initial response. Provide display name of group to logonName property.
Then you can use the _api/web/siteusers endpoint to get security group Id from SharePoint user information list which you will use to grant permissions on site.
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.