What site status are we talking about exactly? Well… is your site created already? Still provisioning? or maybe it already exists?
But how do we know that? And how do we implement that using Power Automate? Let’s dive in! 🙂
What Are the Statuses?
The process of site creation goes through a few stages or may be in a certain stage. When we think about it, we can logically think about that process.
We make a request, then the provisioning happens, and unless the site had already been created before (aka URL is not available), then the site is finally created and we can move on.
We can imagine already the type of flow we’re going to build: “IF this then that. IF that, then this” etc… Although there’s a better way than all those nested conditions for our scenario.
But Why Even Check?
I’ve seen many times when you try to perform other actions (i.e.: create a library, add fields, configure permissions, etc…) and the flow went too fast so the first next action failed! Checking the status of site creation is a good way to add some error handling in your flow(s).
Scenario
Our scenario is going to be as follows:
- If the site is still provisioning, let’s wait for a few seconds or a minute, then create a document library
- If the site has been created (aka available), we’ll create the document library straight away
But how would we know which stage of the creation process we’re in you may ask? 😉
Fortunately for us, Microsoft has published some documentation for us to know exactly where we are in that process: Create Modern Sites.
At the bottom of the page, you’ll see the status codes.
👉 The scenarios are purely for demoing the Switch action and we won’t be using all the available status codes.
Power Automate Flow
Compose
We’ll create 2 compose actions to store some data that will not change.
- SiteURL
- Site template ID (Communication site)

The SiteURL will be used to create the site and check the status against.
Next, we’ll add the Send HTTP request to SharePoint to create our site, using the Outputs of the compose actions accordingly:

Let’s run the flow to see what we’ve got 😉
The flow ran successfully and at the bottom of the raw outputs, we can see the property SiteStatus is 2.

Switch
Instead of having a “hard to read” flow with nested conditions, let’s use a Switch. This is way more appropriate in that scenario.
The switch is going to be based on the SiteStatus property. Then, going back to the documentation, we’ll use the appropriate codes for our scenario.

Then each Case is as follows:


👉 Note that the SiteStatus in each case is a number. Don’t add quotes which will make them strings.
⚠️ As we ran the flow earlier, I have deleted it from the Active Sites. BUT… It’s still in the tenant recycle bin. Let’s see what happens 😉

The flow went to Case 3, where the SiteStatus code was 3: Error. An error occurred while provisioning the site.
Well, we know why 😅 With proper error handling, you could perform more advanced actions, or send an email with the error message.
Let’s delete the site from the tenant recycle bin and retry…
This time, the SiteStatus code was 2: Ready. The site has been created. Therefore, subsequent actions can be performed

👉 My first HTTP request to SharePoint is non-destructive or non-terminating. Meaning running the flow again will not generate an error because the site exists. But if you check the SiteId, it will be the same.
There are other status codes available for your flows (most likely to be used with a specific condition) depending on what you’re trying to check overall.
Checking the status is very handy when you have a lot of actions/creations to perform, with Apply to each loops, etc. That’s a first step into the error handling world!
Thanks for reading! 🙂