Deleting a SharePoint Team Site using Power Automate

Viewed 19

I have a Power Automate workflow that is doing a lot of different things, and at the end, it tries to delete a Team Site (site collection) in my SharePoint Online tenant. I am using an HTTP action to do this, and it looks like this:

Site Address: https://xxx.sharepoint.com/sites/yyy
Method: POST
Uri: _api/web
Headers:
"accept": "application/json;odata=verbose"
"content-type": "application/json;odata=verbose"
"X-HTTP-Method": "DELETE"

The error is

{
  "error": {
    "code": 502,
    "source": "flow-apim-msmanaged-na-westus-01.azure-apim.net",
    "clientRequestId": "1ed0536f-78f3-45cc-a636-a10af5d670f0",
    "message": "BadGateway",
    "innerError": {
      "status": 502,
      "message": "Cannot delete top-level site: https://xxx.sharepoint.com/sites/yyy.\r\nclientRequestId: 1ed0536f-78f3-45cc-a636-a10af5d670f0\r\nserviceRequestId: 668965a0-c019-2000-72ee-7660a568e911",
      "source": "https://xxx.sharepoint.com/sites/yyy/_api/web",
      "errors": [
        "-2146232832",
        "Microsoft.SharePoint.SPException"
      ]
    }
  }
}

Is this possible from Power Automate, and if so, what should I be doing differently?

1 Answers

If it is a modern site (Communication sites and Non-group associated Team Sites) you should be able to use the _api/SPSiteManager endpoint in a Send an HTTP request to SharePoint action.

Delete a modern site

url: /_api/SPSiteManager/delete
method: POST
accept: application/json;odata.metadata=none
odata-version: 4.0
body:
{
  "siteId":"d11e59ca-1465-424c-be90-c847ba849af5"
}

When it is a group connected site I would use the Delete Group method from the Graph API in a Send an HTTP request action of the Office 365 Groups connector.

DELETE https://graph.microsoft.com/v1.0/groups/{id}
Related