Creation of a Group:
Rest API to create a group is
Uri: /_api/Web/SiteGroupsMethod: POSTHeader: {content-type:'application/json; odata=verbose'}Body:{"__metadata": {"type": "SP.Group"},"Title": "Demo Group - Contribute","Description": "Created through API in Flows."
}
We refer the above API call in Flow action: Send an HTTP Request to Sharepoint as in below
Set Permissions to Sharepoint Group:
Rest API to set Permissions for a group / user is
Uri: /_api/web/roleassignments/addroleassignment(principalid=<<PrincipalID>>, roledefid=<<PermisisonRoleID>>)Method: POST
Here, PrincipalID is the ID of group created in above action. we can fetch this in Flow as body('HTTP_-_Create_Group')?['d']?['Id']
And, RoleDefID is the ID of permission role we are looking to assign. In sharepoint, each permisison role has an internal ID. We can find them by accessing Rest API /_api/web/roledefinitions
Here, for Contribute, the RoleID is 1073741827
Add Users to a Sharepoint Group:
Rest API to add users to a Sharepoint group is
Uri:/_api/web/sitegroups/GetById(<<GroupID>>)/usersMethod: POSTHeader: {content-type:'application/json; odata=verbose'}Body: {"__metadata": {"type": "SP.User"},"LoginName": "<<LoginName of User>>"}
We already have GroupID from the first action and for user, we need Login Name of it.
Once we execute it, it creates a group and adds user as in below
If we have multiple user accounts, we can add them to an array and use loop action for this API. Or, use BULK API to merge all calls except the first one as we need GroupID for other service calls. For Bulk API, I have provided demo in my previous post Set Permissions on a Sharepoint list Item
No comments:
Post a Comment