SharePoint Site Scripts and Site Designs in Power Automate Microsoft Office 365 image 6

When you look at SharePoint site provisioning solutions, you will quite quickly bump into Site Scripts and Site Designs. In this post some options on handling these in Power Automate

Site Designs and Site Scripts

Site scripts are nothing more than some json text describing the changes that you want to make to your site. When you provision a site you can specify the script that you want to apply to the site and then the changes will happen. In the above mentioned article you will find the PowerShell options to apply your script to your site.

But what if,…

…, you want to update your project sites using Power Automate?

The starting point of implementing Site Scripts and Site Designs using Power Automate is the Site design and site script REST API.

In this post I’ve looked at

  1. Create a site script
  2. Delete a site script
  3. Create a site design
  4. Delete a site design
  5. Apply the site design to a site.

For all the example flows I created a variable in my solution that is set to the URL of the SharePoint admin center.

https://mytenant-admin.sharepoint.com/

Create a Site Script

Further down this post I will create an app in Power Apps to handle the editing of the site script. So fro now i will just assume that the script is passed into the flow using a parameter on the Power Apps trigger.

SharePoint Site Scripts and Site Designs in Power Automate Microsoft Office 365 image 1

Then the flow will call the following endpoint:

/_api/Microsoft.SharePoint.Utilities.WebTemplateExtensions.SiteScriptUtility.CreateSiteScript(Title=@title)?@title='@{triggerBody()['text']}'

And in the body I’m supplying the site script itself.

Delete a Site Script

In production environments you might needs to be careful deleting site scripts, but as I was developing the app it was useful to delete the test scripts that I added to my tenant every now and then.

The flow is following the same pattern again.

  • A Power Apps trigger
  • A HTTP request action and
  • A respond back to my app.
SharePoint Site Scripts and Site Designs in Power Automate Microsoft Office 365 image 7

Using the following endpoint to delete the site script and supplying the id in the body of the request and my site script will be deleted in now time.

/_api/Microsoft.SharePoint.Utilities.WebTemplateExtensions.SiteScriptUtility.DeleteSiteScript

Create Site Design

Now we’re getting to the site design. The site design can be a collection of one or more site scripts. These Site designs are what you would apply to the site. Before, the design can be applied to the site however, we will need to create a site design.

To do this we need to supply the Title and Description of the site.

We also need to tell the system if we are planning to apply this to a Team site or a Communication site. A team site uses 64 and the web template for a communication site is 68. These two templates are probably the most used ones but there are more templates available:

ParameterValueSite template type
WebTemplate64Team site template
WebTemplate 11Team site (with group creation disabled)
WebTemplate68Communication site template
WebTemplate69Channel site template

Now all that there is left to do, is adding the Script Id that we got from the creation of the site script flow.

SharePoint Site Scripts and Site Designs in Power Automate Microsoft Office 365 image 3

The above endpoint used is:

/_api/Microsoft.SharePoint.Utilities.WebTemplateExtensions.SiteScriptUtility.CreateSiteDesign

Delete a site design

The deletion of the site design is similar to the deletion of the site script. Other than the endpoint there isn’t anything different

SharePoint Site Scripts and Site Designs in Power Automate Microsoft Office 365 image 4

Apply a site design

Now the final step.Applying the site design.

Using the Design Id that the Design creation flow gave us, we can now apply that design to a site which we supply the URL for.

Using the following endpoint in the HTTP request action:

/_api/Microsoft.SharePoint.Utilities.WebTemplateExtensions.SiteScriptUtility.ApplySiteDesign

And in the body, we take the parameters from the trigger of the flow. And our flow to apply the design is ready

{
"siteDesignId": "@{triggerBody()['text']}", "webUrl":"@{triggerBody()['text_1']}"
}
SharePoint Site Scripts and Site Designs in Power Automate Microsoft Office 365 image 5

Create an app Power Apps

Now all I have to do is create an app in Power Apps that lets me edit a site script in an Text Input control. Then on the Create Scrip button I can call the flow to create the script inside my tenant.

Then the Create Site Design button will call the relevant flow to create a site design.

And finally the Apply script to site will take the URL that I entered and will apply my site design.

Site scripts applied from Power Apps

This is all quite easy, well at least it looks easy.

But what if you have a 1000 project sites and all of them need to be updated with new list?

Well it doesn’t get any more complicated than my example in this post.All you now need to make sure is that you go through all the project sites in your environment and apply the same site design to the sites.

By Pieter Veenstra

Business Applications and Office Apps & Services Microsoft MVP working as a Microsoft Productivity Principal Consultant at HybrIT Services. You can contact me using contact@veenstra.me.uk.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: