Power Community

Power Community

How to get Site templates (Site Design) via Power Automate

In my previous blog post, I explained how to Apply Site template (Site Design) in this one I would like to show How to get Site templates (Site Design) via Power Automate. I know that it can be done also in other ways, but I like to push Power Automate and check what is possible 😁.


Table of content:


Configuration of Get Site templates (Site Design) Flow

Trigger

Starting with Manually trigger a flow and updating this trigger with one Input property. SiteAddress property will give me flexibility to move it across different tenants.

Send an HTTP Request to SharePoint

Second step for me will be Send an HTTP Request to SharePoint action with following configuration:

  • Site Address: the value of the Input SiteAddress from trigger
  • Method: POST
  • Uri:
_api/Microsoft.SharePoint.Utilities.WebTemplateExtensions.SiteScriptUtility.GetSiteDesigns
  • Headers: N/A
  • Body: N/A

Condition

After that, I’m doing check if the returned value is not empty, so next steps in my Flow won’t fail:

Left side of condition is:

empty(body('GetSiteDesigns')?['d']?['GetSiteDesigns']?['results'])

Empty function gives boolean results true or false and I want to carry on only for false outcome (have values in results) thus right side of condition.

d.GetSiteDesigns.results explained (at least trying)

I wouldn’t be me not trying to explain above. Result of the GetSiteDesigns post method looks like this:

"body": {
        "d": {
            "GetSiteDesigns": {
                "__metadata": {
                    "type": "Collection(Microsoft.SharePoint.Utilities.WebTemplateExtensions.SiteDesignMetadata)"
                },
                "results": [
                    {
                        "Description": null,
                        "DesignPackageId": "00000000-0000-0000-0000-000000000000",
                        "DesignType": "0",...

I (and anyone else) working with the results of the GetSiteDesigns could use sample return to Parse Json, but I think here there is no need to do it. After checking the first execution of GetSiteDesigns I knew that I need to check results array to carry on or stop Flow.

In above sample results is array nested in GetSiteDesigns and GetSiteDesigns node is part of d which is in body node 😀. Body is one of the properties to which I have access:

After adding it to Condition action, I needed only right path to location (did that in Expression editor) in my object, thus:

body('GetSiteDesigns')?['d']?['GetSiteDesigns']?['results']

is giving me access to content which I’m wanted to use.

TIP
This might look scary, but after a little of experience and practice such an object will be easy to read and to work with. Just check out any introduction material about JSON.

Select

If I get the results, so the call found Site templates (Site Designs) I want to get properties which are interesting for me. To achieve such a result, I’m adding Select action:

  • From property (the same expression as in the empty function, this time in copy/paste ready version 😎)
@{body('GetSiteDesigns')?['d']?['GetSiteDesigns']?['results']}
  • Map property:
{
  "Title": @{item()?['Title']},
  "WebTemplateID": @{item()?['WebTemplate']},
  "Template ID": @{item()?['Id']}
}

TIP
Select action Map property is working in the two modes, text mode and key value. To change the mode, click the icon in the right corner:

My data are added in the text mode. As I explained, results is the array and I added it to From property of Select action. Thanks to that using item function I can inform Power Automate which properties of the results item I want to take. For me, it was only Title, WebTemplate and of course ID of Site templates (Site Design).

NOTE: Below I explained why decided to also pick the WebTemplate property.

If it would be beneficial, I can add to my GitHub all of the properties which are returned from the call, just let me know.

TIP
Interesting is that you can also get the list of the Site Scripts which are part of the Site Template, just refer to SiteScriptsIds property:

Create CSV table

Next step is simple in configuration, to From I’m adding Output of the Select. I decided to use CSV table as it is giving me the chance to do quick review. Of course, results can be stored in other formats.

Send an email (V2)

To deliver CSV file, I decided to use Outlook action to Send an email (V2):

Nothing fancy here 😋 just remember to add the Output of Create CSV table as the Attachments Content and give some kind of name to Attachments Name property ending with .csv


WebTemplate property

I think it is also worth to mention why WebTemplate property is important. Depending on its value, we can use it for different SharePoint sites:

  • 64 – Team site
  • 68 – Communication site
  • 1 – Team site (with group creation disabled)
  • 69 – Channel site template

That means Site template (Site Design) can be applied only for correct site type.


Execution

I’m ready with my Flow, going to run it. Click Run and providing my SiteAddress:

Flow finish fast and I’m getting email with csv file:

Bonus time: you can download this Flow from my GitHub just click here.


Summary

I hope that How to get Site templates (Site Designs) via Power Automate will fill the gap created in how to Apply Site template (Site Design)

Additionally, I manage to cover a small explanation of how to work with objects returned from HTTP requests send to SharePoint, as presented not always Parse Json is required.

Plus presented how to read with Select items of arrays in such objects.

As the bonus I’m sharing the whole Flow at my GitHub with that said I hope How to get Site templates (Site Designs) via Power Automate will be useful.

Thanks for reading and have a great day 😊

This post was originally published on this site

- Advertisement -spot_img

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -spot_img
- Advertisement - Advertisement

Latest News

SharePoint Roadmap Pitstop: November 2022

Gobble, gobble - time to gobble up all the updates that landed for SharePoint and related tech in the...

More Articles Like This

- Advertisement -spot_img