0

Is it possible to add an existing SharePoint group to a SharePoint site via SharePoint request action in Power Automate [or alternatively SP REST API]?

I have only seen how to create a new group and add it to a site.

4
  • What kind of group do you mean? AD Security Group? SharePoint Group? M365 group? Commented Apr 16, 2021 at 17:33
  • 1
    @DenisMolodtsov apologies, a SharePoint Group. Although if easier, I could use an AD Group. I will edit for clarity. Commented Apr 16, 2021 at 17:34
  • You mean you want to assign the permissions to existing SharePoint group using REST API? Commented Apr 16, 2021 at 17:39
  • hi @GaneshSanap, no. I have a site collection with subsites under it. Subsites are created adhoc and do not inherit from the top-level site. I would like to dynamically add a Leadership group created at the top level site to every subsite. Commented Apr 16, 2021 at 17:45

2 Answers 2

1

You can assign permissions to SharePoint group using SharePoint REST API like:

function setPermissionForGroup(){
    $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/roleassignments/addroleassignment(principalid=<GroupId>, roledefid=1073741827)",
        type: "POST",
        contentType: "application/json;odata=verbose",
        headers: { "Accept": "application/json; odata=verbose","X-RequestDigest": $("#__REQUESTDIGEST").val(),"X-HTTP-Method": "POST" },
        success: function (data) {
            alert('Contribute permission set on group');
        },
        error: function (data) {
            alert("Error: " + JSON.stringify(data));
        }
    });
});

Replace <GroupId> with the ID of SharePoint group. Open the SharePoint group & you will find the group ID in browser URL:

enter image description here

roledefid for Permission Levels are as follows:

  • Full Control: 1073741829
  • Design: 1073741828
  • Edit: 1073741830
  • Contribute: 1073741827
  • Read: 1073741826
  • Limited Access: 1073741825
  • View Only: 1073741924

You need to convert above REST call in Power Automate Send an HTTP request to SharePoint action.

2
  • Hello Ganesh, thanks. This doesn't meet the ask... The group does not exist on the site I would like to add it, too. In order to do role assignment, the group needs to already exist on the site. I am taking a group from a parent site, and I'd like to add it to a child site. Commented Apr 16, 2021 at 17:48
  • 1
    If they are subsites then the groups that exist at site collection level (top level) will exist at subsite level as well, regardless of whether you are inheriting permissions or not. Ganesh is correct, you just need to assign the permission to the group. You can see all the groups by going to /_layouts/15/groups.aspx at subsite level. Commented Apr 17, 2021 at 15:50
0

If the group doesnot exist on the site, you could use the EnsureUser method to add the group to a site: https://docs.microsoft.com/en-us/previous-versions/office/sharepoint-visio/jj245233(v=office.15)?redirectedfrom=MSDN

http://<sitecollection>/<site>/_api/web/ensureUser(logonName)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.