Update Site Sharing Capability with Flow > How to use "admin.sp.com/_api/Tenant/Sites/Update"

Copper Contributor

Hello everyone,

 

As admin, I need to update the sharing capability of a SharePoint site using Power Automate.

external-sharing-site

I have not figured out a way of doing this with Graph API so I am now trying with SharePoint REST API.

 

Using, "Send an HTTP request to SharePoint", I can read the current setting on https://mytenant-admin.sharepoint.com/_api/Microsoft.Online.SharePoint.TenantAdministration.Tenant/S... but I can't use the Update method with POST.

 

Does anyone know how to do this?

 

Thanks !

7 Replies

@alextest how about PUT or, probably better use PATCH? Please try on non-production first.

In case someone looking for a solution, this is how I manage to solve this:

you need to use admin API, the URL of the admin API is 

https://{tenant name}-admin.sharepoint.com/

you will need the site ID of the site that you want to change the sharing setting.

in your power automate add a new 'Send HTTP request to SharePoint'

 

Site address: https://{tenant name}-admin.sharepoint.com/

Method: Post

Uri: _api/Microsoft.Online.SharePoint.TenantAdministration.Tenant/Sites('{Site ID}')

Headers:

  • accept  :   application/json;odata=verbose
  • content-type:    application/json;odata=verbose
  • X-HTTP-Method:     MERGE

Body:

{
"__metadata": {
"type": "Microsoft.Online.SharePoint.TenantAdministration.SiteProperties"
},
"SharingCapability": 1
}

Matt_majedi_0-1623753864470.png

 

 

@Matt_majedi 

Hi,

https://{tenant}-admin.sharepoint.com/ not accepted as "Site Address" on "Send an HTTP request to Sharepoint"

Error: We are unable to find the site address. Please try selecting a site address from the dropdown.

@OmarSeri Replace {tenant} in URL with the actual name of your tenant where you are creating the flow. For example: 

 

https://contoso-admin.sharepoint.com

 

And add it as a custom value like: 

ganeshsanap_0-1678949648552.png


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.

For SharePoint/Power Platform blogs, visit: Ganesh Sanap Blogs

@ganeshsanap 

I am facing the following error , any idea with, 

{
  "status"403,
  "message""Attempted to perform an unauthorized operation.\r\nclientRequestId: 662df67a-2e53-45a0-b2ab-634addd3905a\r\nserviceRequestId: bca1c5a0-b02c-2000-7833-e0b461d0e560",
  "errors": [
    "-2147024891",
    "System.UnauthorizedAccessException"
  ]
}
 
hemanth1595_0-1689145389709.pnghemanth1595_1-1689145405226.png

connection account has sharepoint admin role, this flow is triggered from the power app, and the users running the power app doesn't have admin role. I think user doesn't require admin role as I have already have a connection to that action.

@hemanth1595 When you run the flow from Power Apps, flow automatically uses the credentials of user running the flow from Power Apps. Hence you are facing this issue.

 

To avoid this issue, you have to use the Run only users permissions on the flow. 

  1. Go to flow details page
  2. Click on Edit next to Run only users section: ganeshsanap_0-1689150650830.png
  3. Change the SharePoint connection with admin user connection and click Save: ganeshsanap_1-1689150838875.png

Note: All actions using the SharePoint connector will run with the admin user account now.


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.