Managing collaboration spaces in SharePoint often requires creating multiple subsites with a consistent structure. Doing this manually is repetitive and error-prone. A more robust approach is to define a site template once, register it in the tenant, and then automate subsite creation using Power Automate with the SharePoint REST API.
Automating SharePoint Subsite Provisioning with Site Designs and Power Automate
Introduction
Managing collaboration spaces in SharePoint often requires creating multiple subsites with a consistent structure. Doing this manually is repetitive and error-prone. A more robust approach is to define a site template once, register it in the tenant, and then automate subsite creation using Power Automate with the SharePoint REST API.
This article covers both stages:
- Creating and registering a template (Site Design + Site Script).
- Using that template in a Power Automate flow to automatically provision subsites.
Part 1 – Creating a SharePoint Site Template
Step 1. Define a Site Script
A Site Script is a JSON file that describes the actions SharePoint should perform when the template is applied.
Example (ContosoProjectScript.json):
{
"$schema": "schema.json",
"actions": [
{
"verb": "createSPList",
"listName": "ProjectDocuments",
"templateType": 101,
"subactions": [
{
"verb": "setDescription",
"description": "Document library for project files"
}
]
},
{
"verb": "applyTheme",
"themeName": "ContosoTheme"
}
],
"version": 1
}
This script creates a custom document library and applies a theme.
Step 2. Upload the Site Script
Using SharePoint Online PowerShell:
Connect-SPOService -Url https://contoso-admin.sharepoint.com
$script = Add-SPOSiteScript `
-Title "Contoso Project Script" `
-Description "Creates project library and applies Contoso theme" `
-Content (Get-Content .\ContosoProjectScript.json -Raw)
This command registers the script in the tenant and returns a GUID.
Step 3. Create a Site Design
Link the Site Script to a Site Design.
Add-SPOSiteDesign `
-Title "Contoso Project Template" `
-WebTemplate "64" `
-SiteScripts $script.Id `
-Description "Template for Contoso project collaboration sites"
Title→ Friendly name of the template.WebTemplate "64"→ Indicates it applies to a Team site.SiteScripts→ GUID(s) of associated scripts.
This creates the Site Design and assigns another GUID, which identifies the template.
Step 4. Verify the Template
Check all templates available in the tenant:
Get-SPOSiteDesign
Expected output:
Id Title WebTemplate
----------------------------------- -------------------------- ------------
12345678-90ab-cdef-1234-567890abcdef Contoso Project Template 64
Part 2 – Automating Subsite Creation with Power Automate
Step 1. Store the Template Reference
In the Power Automate flow, define a variable containing the template reference:
- Variable Name:
strTemplate - Value:
{12345678-90ab-cdef-1234-567890abcdef}#ContosoProjectTemplate
This reference combines:
- The GUID of the Site Design.
- The logical name of the template.
Step 2. Send HTTP Request to SharePoint
Add an action Send an HTTP request to SharePoint.
- Method:
POST - Uri:
/_api/web/webinfos/add - Headers:
Accept: application/json;odata=verbose Content-Type: application/json;odata=verbose - Body Example:
{ "parameters": { "__metadata": { "type": "SP.WebInfoCreationInformation" }, "Url": "DemoSubsite", "Title": "Contoso Business Unit", "Description": "Automatically created subsite", "Language": "1033", "WebTemplate": "{12345678-90ab-cdef-1234-567890abcdef}#ContosoProjectTemplate", "UseUniquePermissions": false } }
How It Works
- The flow sets variables for the subsite name, title, and template.
- The SharePoint REST API is called with
/webinfos/add. - SharePoint provisions a new subsite using the registered Site Design.
Key Takeaways
- Site Scripts are JSON definitions of configuration actions.
- Site Designs are published templates in the tenant that reference one or more Site Scripts.
- Power Automate can consume these designs by calling the SharePoint REST API and providing the correct template reference.
- This approach provides consistent, automated provisioning of subsites aligned with organizational standards.
