Set a SharePoint Group owner with Power Automate

Set a SharePoint Group owner with Power Automate

I know SharePoint Groups are not fashion any more, and a lot of people prefer using Sharing links to grant access to specific people, but I still find the SharePoint Groups very useful to centralize access to multiple SharePoint artefacts.

I thought this would be quite simple using the SharePoint HTTP Request action but, something is wrong with the SharePoint REST group/owner endpoint ☹ And I found it impossible to make it work !!

But…  we do have a solution !! Everything is going to be done using the STANDARD Power Automate action : “Send an HTTP request to SharePoint”

Set a SharePoint Group owner with Power Automate

The account executing the action (connected through the SharePoint Online connection in Power Automate) needs to have the high enough priviledge to create SharePoint groups in your SharePoint site. 

Create a SharePoint Group

Create a SharePoint Group with Power Automate is quite easy using the SharePoint HTTP Request action :

POST /_api/web/SiteGroups

{
    "Title": "Custom SharePoint Group ",
    "Description": "This is my SharePoint group created from Power Automate"
} 
Set a SharePoint Group owner with Power Automate

Get the SharePoint site’s default Owner group

In most case, we want the SharePoint Site default Owner Group to be the owner of each SharePoint Groups, so they can manage all access rights. To do so, we need to retrieve the SharePoint “Associated Owner Group”, and it can be done pretty easly using the SharePoint HTTP Request action :

GET _api/web/associatedownergroup 
Set a SharePoint Group owner with Power Automate

Most of the SharePoint HTTP Request action responses have a pretty complex structure. Using the Parse JSON Action for responses will make your job a lot easier in your next Flow steps to reference previous SharePoint HTTP Request outputs.

You don’t have to know the schema, you should run your Flow a first time, copy the body of the “GetSiteOwnerGroup” action, and paste it into the “Generate from sample” window of the Parse JSON action.

Set a SharePoint Group owner with Power Automate

Set the SharePoint Group owner

Let’s use some “old fashion” SharePoint Client Query Protocol !

We’ll need 3 inputs :

  • The collection site ID where the SharePoint group is
  • The SharePoint group ID you want to assign as your group owner
  • The SharePoint group ID you want to set the ownership

The output of the 2 previous steps returns the 2 SharePoint groups ID we need, we just have to retrieve the SharePoint Site ID using SharePoint HTTP request once again.

GET _api/site/id 

Now that we have everything, let’s build our XML for the SharePoint Client Query Protocol. The syntax and logic is quite more complex than REST Request.

Here is our Body to set a SharePoint Group Owner :

<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="15.0.0.0" ApplicationName=".NET Library" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009">
    <Actions>
        <SetProperty Id="1" ObjectPathId="2" Name="Owner">
            <Parameter ObjectPathId="3" />
        </SetProperty>
        <Method Name="Update" Id="4" ObjectPathId="2" />
    </Actions>
    <ObjectPaths>
        <!--siteId:g:groupId SPO Group to update-->
        <Identity Id="2" Name="740c6a0b-85e2-48a0-a494-e0f1759d4aa7:site:<SPO_SITE_ID>:g:<SPO_GROUP_TO_UPDATE_ID>" />
        <!--siteId:g:groupId Owner Group-->
        <Identity Id="3" Name="740c6a0b-85e2-48a0-a494-e0f1759d4aa7:site:<SPO_SITE_ID>:g:<SPO_GROUP_OWNER>" /> 
    </ObjectPaths>
</Request> 

If you have exactly the same previous actions name that I have, you can copy/past directly this piece of XML in a “Compose” Power Automate action. 

<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="15.0.0.0" ApplicationName=".NET Library" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009">
    <Actions>
        <SetProperty Id="1" ObjectPathId="2" Name="Owner">
            <Parameter ObjectPathId="3" />
        </SetProperty>
        <Method Name="Update" Id="4" ObjectPathId="2" />
    </Actions>
    <ObjectPaths>
        <!--siteId:groupId SPO Group to update-->
        <Identity Id="2" Name="740c6a0b-85e2-48a0-a494-e0f1759d4aa7:site:@{body('ParseSiteId')?['d']?['Id']}:g:@{body('ParseCreatedGroup')?['d']?['Id']}" />
        <!--siteId:groupId Owner Group-->
        <Identity Id="3" Name="740c6a0b-85e2-48a0-a494-e0f1759d4aa7:site:@{body('ParseSiteId')?['d']?['Id']}:g:@{body('ParseSiteOwnerGroup')?['d']?['Id']}" /> 
    </ObjectPaths>
</Request> 

Then we just have to run a SharePoint REST Request using the standard “Send an HTTP request to SharePoint”, and use our XML as a body

POST /_vti_bin/client.svc/ProcessQuery 

About the Author:

Hi ! I’m Théophile Chin-Nin, Microsoft 365 & Power Platform Architect and Microsoft Business Application MVP, from Nantes, France.

Reference:

Chin-Nin, T. (2020). Set a SharePoint Group owner with Power Automate. Available at: https://tchinnin.com/set-a-sharepoint-group-owner-with-power-automate/ [Accessed: 2nd March 2021].

Find more great Power Platform content here.

Share this on...

Rate this Post:

Share: