SOLVED

Add a security group as a member of a teamsite by flow.

Copper Contributor

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?

15 Replies

@HoSFonnan You can use HTTP request action and REST API to add user to SharePoint group. Follow below links for more information:

  1. https://www.codesharepoint.com/rest-api/add-user-to-site-group-in-sharepoint-using-rest-api
  2. https://stackoverflow.com/questions/68549333/not-able-to-add-user-to-sharepoint-group-using-rest-api
  3. https://sharepoint.stackexchange.com/questions/219150/add-a-user-to-sp-group-using-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.

This is not the problem.

I want to add an existing security group automatically to a teams site.

@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.

Sorry for not being clear ^^

I want to add securrity group under site permissions

@HoSFonnan Use flow like this: 

ganeshsanap_0-1663854333751.png

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.

@ganeshsanap Hi, 

But i cant add an existing domain/security group with this flow? 

Skärmbild 2022-09-26 130451.png

I want to add this group automatic when you create a new site. 

After I test run your example flow i get this result: 
Skärmbild 2022-09-26 130800.png

 

@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.

@ganeshsanap 

 

 

@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.

@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.

Hi again,
This is what i want:
Copy Domain and security groups from "site A" and use the same groups on "site B"

With your commands/code. It return the value of null. Because the group is not existing on the new site.
best response confirmed by HoSFonnan (Copper Contributor)
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.

Thank you for the help!
It works now!

Hi again, @ganeshsanap 

 

Quick question. 

Could you apply this to folders aswell in SharePoint? 

@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.

1 best response

Accepted Solutions
best response confirmed by HoSFonnan (Copper Contributor)
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.

View solution in original post