Adding a Site Collection Administrator via Power Automate


In SharePoint Online, you can automate the site creation process and add a site collection administrator (SCA) using Power Automate and the SharePoint REST API.

This guide will show you how to use the “Send an HTTP Request to SharePoint” action in Power Automate to grant SCA permissions to a user on a new or existing SharePoint modern site. Follow these steps to add an SCA with Power Automate:

Step 1: Create a new instant cloud flow with a manual trigger in your Power Automate tool.

Step 2: First, we need to add the user to the site’s hidden User Information List using the EnsureUser method in the SharePoint REST API. This method verifies if the user exists in the site collection and adds them if they don’t. Use the “Send an HTTP Request to SharePoint” action in Power Automate to achieve this.

Step 3: Next we will use the following configurations for each field in the Send HTTP Request action card:

Method: POST

Uri: _api/web/ensureuser

Headers:
{
	"content-type": "application/json;odata=verbose",
	"accept": "application/json;odata=verbose"
}

Body:
{
	'logonName': 'test@organization.com'
}


Step 4: Next, retrieve the SharePoint user ID from the User Information List to grant site collection administrator permissions. Add a Compose action to extract the user ID from the EnsureUser method’s outputs. Use the following expression in the Compose action’s Inputs to get the user ID:

@{body('HTTP_-_EnsureUser')?['d']?['Id']}


Step 5: Finally, update the user’s IsSiteAdmin property to true to grant site collection administrator rights. Add another Send an HTTP request to SharePoint action in Power Automate with the following configuration:

Method: POST

Uri: _api/web/ensureuser

Headers:

{
	"content-type": "application/json;odata=verbose",
	"accept": "application/json;odata=verbose"
}
Body:

{
	'logonName': 'pattif@contoso.com'
}

Finally the Power Automate flow should resemble the flow format shown below:


Step6: Save and run your flow using the Test > Manually options at the top right. Once completed successfully, the user will be added as a Site Collection Administrator to your SharePoint site.

Spread the word

Leave a Reply