Easy way to check Site creation status with Power Automate

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.

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:

⚠️ 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

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! 🙂

Discover more from Veronique's Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading