Credits : This article was originally published on the Microsoft Wiki.
Introduction
Power Automate provides Variables of different datatypes like Boolean, Integer, Float, String, Object and Array to provide a storage mechanism with the running flow. In this article, we will see how we can use the variable of type object to work with a business use case in Power Automate
When we use the Send an HTTP Request to SharePoint action to create a new site, it creates the site and shares back a result body which does not natively contain the success status. We get the result back as:
As per the official documentation of the Site Creation API, the Site Status can potentially four (4) values depending on the Success or Failure of the action:
0 - Not Found. The site doesn't exist.
1 - Provisioning. The site is currently being provisioned.
2 - Ready. The site has been created.
3 - Error. An error occurred while provisioning the site.
In such a situation, Having this table maintained as a Variable Object will help us cross-check the returned Site Status against the variable to pick the status and intimate an end user.
Implementation
To test this scenario, we will create a manually triggered flow which will accept three (3) text inputs that are required for the site creation. We will accept the Site Title, Site Name and Description from the user while triggering the flow.
We will then declare a Site Status Variable which will contain the Site Status ID and the corresponding Outcome Message as an Object variable.
Let's add the action Send an HTTP request to SharePoint to provision the site. We will issue a POST request to the URI - _api/SPSiteManager/create and keep the Site Address as the SharePoint Admin Center URL. In the Body, we will paste the request payload with the below values:
Title
The Title that should come up in the Site Title bar
URL
The URL where the site should be provisioned, we are getting the Site Address from the user that should come after /sites
Lcid
Locale identifier . By default 1033 is English(United States)
Description
Description for the site obtained from the user
Web template
By default we are creating a communication site which has the web template ID : SITEPAGEPUBLISHING#0
The action will start the site provisioning process and return back the output in the format :
To get the SiteStatus Value from the returned JSON object, we will initialize a string variable- varOutputStatus and extract the value using the expression :
This will fetch the SiteStatus. For instance, if provisioning is complete, the status returned would be two (2). Then, we'll have to fetch the corresponding Status text from the Variable object we have initialized. To fetch this, we'll use the below expression where we'll index into the varStatusCollection with the SiteStatus that we received from the HTTP Action and get back the Site status Text, which we will use in the mail body to intimate the user.
Let us test the flow by triggering it with manual inputs
The Site Creation has been completed now by the HTTP Action and has returned the Site Status as two (2)
We have also received the mail with the Site Status Text that was retrieved from the Variable Object
Summary
Thus, we saw how to use the Array Object in Power Automate using a real-time use case and how to fetch the Site Status code and compare it with the Status Text stored in the Array object to determine the site creation Success/Failure.
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
Community Content feedback
Community Content is an open source project. Select a link to provide feedback: