How to delete Non-Group connected SharePoint sites via PowerAutomate, using the SharePoint API

Dan Jones 0 Reputation points
2023-09-04T13:58:19.4+00:00

Hi all, I have a super simple flow that is manually triggered. The objective of the flow is to delete a Non-Group Connected SharePoint site. I have used the official Microsoft documentation on how to use the REST API, but I keep getting Error 400, bad request errors every time I run the flow when trying to send an http request. I have attached a photo to show the step involved. All of the code, as far as I'm aware, is exactly as the documentation states. but I cannot seem to get the step to complete successfully. There seems to be lots of people having success with group connected SharePoint sites, but as far as I'm aware that's a different process.

NOTE: For the Site Address input, I have tried the URL dynamic content (within screenshot), as well as manually typing the admin centre URL and also manually typing the URL of the site wanting to be deleted. None of the three work.Capture

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,685 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,971 questions
SharePoint Workflow
SharePoint Workflow
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Workflow: An orchestrated and repeatable pattern of business activity, enabling data transformation, service provision, and information retrieval.
583 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Yanli Jiang - MSFT 26,016 Reputation points Microsoft Vendor
    2023-09-07T07:52:55.2366667+00:00

    Hi @Dan Jones ,

    Welcome to Q&A forum!

    I am a SharePoint support engineer, and your question is also related to SharePoint Development, which is not my field of expertise, so I add a related tag so that your question can be seen by SharePoint Development engineers. Regarding your question, I conducted research and testing and got the same results as you. However, I went to the SharePoint admin center to check, and the site has been successfully deleted. You can check to see if the site has been deleted. Because power automate and SharePoint Development are not my areas of expertise, I don't know why this result occurs.

    As another option, you could try using pnp powershell for loop deletion.

    Here is a post you can refer to:

    https://pnp.github.io/cli-microsoft365/sample-scripts/spo/delete-non-group-connected-modern-sites/

    Note: SITEPAGEPUBLISHING#0 and STS#3 are site templates for Communication Site and Non-group associated Team Site respectively. You can change the script according to your needs.

    Hope this helps. :-)


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Yanli Jiang - MSFT 26,016 Reputation points Microsoft Vendor
    2023-09-14T07:59:20.42+00:00

    Hi @Dan Jones ,

    Sorry, the previous reply was wrong. It should be related to SharePoint development, not Graph. I've made corrections to my previous answer. I have conducted research and testing with our colleagues responsible for development. You probably used the wrong site ID. Now I present our complete testing steps. You can compare your own steps and make modifications.

    1, The site used for test:

    User's image

    2, Get the site ID. Here I use graph to obtain it, you can refer to it.

    Go to Graph Explorer, and input like this: https://graph.microsoft.com/v1.0/sites/tenant.sharepoint.com:/sites/sitename?$select=id

    User's image

    Then put the site ID into the body.

    09144

    Run the flow and get success:

    09145

    Double check the site has been deleted:

    09146

    Hope this helps.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.