Create Site Script and Site Template Using Power Automate in SharePoint

Published Sep 07 2021 03:46 AM 1,523 Views
New Contributor

Introduction

Many times, the Site is already created, and we need to apply configuration in the existing site to achieve some level of consistency. How can we achieve it?

To achieve, this kind of implementation, use site template and site scripts to automate provisioning to the existing modern site or create a new site using site templates which is available in your organization tenant.

In the previous version of SharePoint, Site templates were known as site designs.

Site templates are a set of configurations that need to apply on a particular site and Site Scripts are JSON files that include an order list that needs to be executed while we apply it on a Specific SharePoint Site.

Learning Objectives

  1. Create JSON file for Site Scripts
  2. Create Power automate
  3. Create Site Script using REST Call in Power Automate
  4. Create Site Template using REST Call in Power Automate
  5. Output

Prerequisite

  1. M365 environment
  2. Power automate access requires a license
  3. SharePoint Admin Access
  4. Permission
    1. SharePoint Administrator
    2. Site Collection Administrator

Let's get started.

Create JSON file for Site Scripts

You need to create JSON files in specific formats to implement SharePoint artifacts in SharePoint Site.

Available Action includes.
Site Script and Site Template In Power Automate.png

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/site-design-script-actions.schema.json",
  "actions": [
    {
      "verb": "applyTheme",
      "themeName": "Contoso Explorers"
    },
    {
      "verb": "createSPList",
      "listName": "Customer Tracking",
      "templateType": 100,
      "subactions": [
        {
          "verb": "setDescription",
          "description": "List of Customers and Orders"
        }
      ]
    },
    {
        "verb": "setRegionalSettings",
  		"timeZone": 2,
  		"locale": 1050,
        "sortOrder": 0,
  		"hourFormat": "12"
	}
  ],
  "version": 1
}

 

Each action identifies by its "verbName" property and inside auction property, you need to configure the things that you want to apply while creating the site or on an existing site.

 

Create Power automate

Go to https://portal.office.com and click on Power automate.

Click on “New Flow” and Select “Instant Cloud Flow”

Select “Manually Trigger Flow” and Add Name “Create-SiteTemplate-Flow”

Click on Create Button.
Site Script and Site Template In Power Automate11.jpg

 

Create Site Script using REST Call in Power Automate

Initialize variable in power automat to store JSON config.
Flow2.jpg

Select “Send an HTTP request to SharePoint” from the list of actions.
Flow3.jpg

 

Parameters

Site Address - You can select any site Address either it's root or not
Method - post
Url - /_api/Microsoft.SharePoint.Utilities.WebTemplateExtensions.SiteScriptUtility.CreateSiteScript(Title='<Site Script Title Name>')

Headers

 

{
  "Content-Type\n": "application/json;charset=utf-8",
  "accept": "application/json;odata.metadata=minimal",
  "odata-version": "4.0"
}

 

 

Body

@{variables('SiteScript')} // Reference of variable that we Initialized before this action.
Get Create Script ID and store it in Variable

Dips365_1-1630571668730.png

Create Site Template using REST Call in Power Automate

Dips365_0-1630571387332.png

Parameters

Site Address - You can select any site Address either it's root or not
Method - post
Url - /_api/Microsoft.SharePoint.Utilities.WebTemplateExtensions.SiteScriptUtility.CreateSiteDesign

 

Headers

{
  "Content-Type\n": "application/json;charset=utf-8",
  "accept": "application/json;odata.metadata=minimal",
  "odata-version": "4.0"
}

Body

{
    "info": {
        "Title": "<Site Template Title>",
        "Description": "<Site Template Description>",
        "SiteScriptIds": ["@{variables('ScriptID')}"],
        "WebTemplate": "64"
    }
}

The flow looks like as below
Flow6.jpg

Output

Click on the “gear” Icon in SharePoint Site.

Click on “Apply a site template”.

Site Script and Site Template In Power Automate7.gif

 

%3CLINGO-SUB%20id%3D%22lingo-sub-2710696%22%20slang%3D%22en-US%22%3ECreate%20Site%20Script%20and%20Site%20Template%20Using%20Power%20Automate%20in%20SharePoint%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2710696%22%20slang%3D%22en-US%22%3E%3CH4%20id%3D%22toc-hId-344806353%22%20id%3D%22toc-hId-345941203%22%3EIntroduction%3C%2FH4%3E%0A%3CP%3EMany%26nbsp%3Btimes%2C%20the%20Site%20is%20already%20created%2C%20and%20we%20need%20to%20apply%20configuration%20in%20the%20existing%20site%20to%20achieve%20some%20level%20of%20consistency.%20How%20can%20we%20achieve%20it%3F%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CP%3ETo%20achieve%2C%20this%20kind%20of%20implementation%2C%20use%20site%20template%20and%20site%20scripts%20to%20automate%20provisioning%20to%20the%20existing%20modern%20site%20or%20create%20a%20new%20site%20using%20site%20templates%20which%20is%20available%20in%20your%20organization%20tenant.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CP%3EIn%20the%20previous%20version%20of%20SharePoint%2C%20Site%20templates%20were%20known%20as%20site%20designs.%3C%2FP%3E%0A%3CP%3ESite%20templates%20are%20a%20set%20of%20configurations%20that%20need%20to%20apply%20on%20a%20particular%20site%20and%20Site%20Scripts%20are%20JSON%20files%20that%20include%20an%20order%20list%20that%20needs%20to%20be%20executed%20while%20we%20apply%20it%20on%20a%20Specific%20SharePoint%20Site.%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ELearning%20Objectives%3C%2FSTRONG%3E%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3ECreate%20JSON%20file%20for%20Site%20Scripts%3C%2FLI%3E%0A%3CLI%3ECreate%20Power%20automate%3C%2FLI%3E%0A%3CLI%3ECreate%20Site%20Script%20using%20REST%20Call%20in%20Power%20Automate%3C%2FLI%3E%0A%3CLI%3ECreate%20Site%20Template%20using%20REST%20Call%20in%20Power%20Automate%3C%2FLI%3E%0A%3CLI%3EOutput%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CSTRONG%3EPrerequisite%3C%2FSTRONG%3E%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EM365%20environment%3C%2FLI%3E%0A%3CLI%3EPower%20automate%20access%20requires%20a%20license%3C%2FLI%3E%0A%3CLI%3ESharePoint%20Admin%20Access%3C%2FLI%3E%0A%3CLI%3EPermission%3COL%3E%0A%3CLI%3ESharePoint%20Administrator%3C%2FLI%3E%0A%3CLI%3ESite%20Collection%20Administrator%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3ELet's%20get%20started.%3C%2FP%3E%0A%3CH5%20id%3D%22toc-hId-1035367827%22%20id%3D%22toc-hId-1036502677%22%3ECreate%20JSON%20file%20for%20Site%20Scripts%3C%2FH5%3E%0A%3CP%3EYou%20need%20to%20create%20JSON%20files%20in%20specific%20formats%20to%20implement%20SharePoint%20artifacts%20in%20SharePoint%20Site.%3C%2FP%3E%0A%3CP%3EAvailable%20Action%20includes.%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Site%20Script%20and%20Site%20Template%20In%20Power%20Automate.png%22%20style%3D%22width%3A%20561px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F307564i79ECC19368EDE4C5%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Site%20Script%20and%20Site%20Template%20In%20Power%20Automate.png%22%20alt%3D%22Site%20Script%20and%20Site%20Template%20In%20Power%20Automate.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%7B%0A%20%20%22%24schema%22%3A%20%22https%3A%2F%2Fdeveloper.microsoft.com%2Fjson-schemas%2Fsp%2Fsite-design-script-actions.schema.json%22%2C%0A%20%20%22actions%22%3A%20%5B%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%22verb%22%3A%20%22applyTheme%22%2C%0A%20%20%20%20%20%20%22themeName%22%3A%20%22Contoso%20Explorers%22%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%22verb%22%3A%20%22createSPList%22%2C%0A%20%20%20%20%20%20%22listName%22%3A%20%22Customer%20Tracking%22%2C%0A%20%20%20%20%20%20%22templateType%22%3A%20100%2C%0A%20%20%20%20%20%20%22subactions%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%22verb%22%3A%20%22setDescription%22%2C%0A%20%20%20%20%20%20%20%20%20%20%22description%22%3A%20%22List%20of%20Customers%20and%20Orders%22%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22verb%22%3A%20%22setRegionalSettings%22%2C%0A%20%20%20%20%22timeZone%22%3A%202%2C%0A%20%20%20%20%22locale%22%3A%201050%2C%0A%20%20%20%20%20%20%20%20%22sortOrder%22%3A%200%2C%0A%20%20%20%20%22hourFormat%22%3A%20%2212%22%0A%20%7D%0A%20%20%5D%2C%0A%20%20%22version%22%3A%201%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EEach%20action%20identifies%20by%20its%20%22verbName%22%20property%20and%20inside%20auction%20property%2C%20you%20need%20to%20configure%20the%20things%20that%20you%20want%20to%20apply%20while%20creating%20the%20site%20or%20on%20an%20existing%20site.%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId-1024864723%22%20id%3D%22toc-hId-1025999573%22%3ECreate%20Power%20automate%3C%2FH4%3E%0A%3CP%3EGo%20to%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fportal.office.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fportal.office.com%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%20click%20on%20Power%20automate.%3C%2FP%3E%0A%3CP%3EClick%20on%20%E2%80%9CNew%20Flow%E2%80%9D%20and%20Select%20%E2%80%9CInstant%20Cloud%20Flow%E2%80%9D%3C%2FP%3E%0A%3CP%3ESelect%20%E2%80%9CManually%20Trigger%20Flow%E2%80%9D%20and%20Add%20Name%20%E2%80%9CCreate-SiteTemplate-Flow%E2%80%9D%3C%2FP%3E%0A%3CP%3EClick%20on%20Create%20Button.%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Site%20Script%20and%20Site%20Template%20In%20Power%20Automate11.jpg%22%20style%3D%22width%3A%20850px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F307566i0748A275365DA228%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Site%20Script%20and%20Site%20Template%20In%20Power%20Automate11.jpg%22%20alt%3D%22Site%20Script%20and%20Site%20Template%20In%20Power%20Automate11.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId--782589740%22%20id%3D%22toc-hId--781454890%22%3ECreate%20Site%20Script%20using%20REST%20Call%20in%20Power%20Automate%3C%2FH4%3E%0A%3CP%3EInitialize%20variable%20in%20power%20automat%20to%20store%20JSON%20config.%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Flow2.jpg%22%20style%3D%22width%3A%20561px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F307567i21638EB7205FEE9A%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Flow2.jpg%22%20alt%3D%22Flow2.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ESelect%20%E2%80%9CSend%20an%20HTTP%20request%20to%20SharePoint%E2%80%9D%20from%20the%20list%20of%20actions.%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Flow3.jpg%22%20style%3D%22width%3A%20561px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F307568i7415E92FD3BEB73C%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Flow3.jpg%22%20alt%3D%22Flow3.jpg%22%20%2F%3E%3C%2FSPAN%3E%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EParameters%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3ESite%20Address%20-%26nbsp%3BYou%20can%20select%20any%20site%20Address%20either%20it's%20root%20or%20not%3CBR%20%2F%3EMethod%20-%26nbsp%3Bpost%3CBR%20%2F%3EUrl%20-%26nbsp%3B%2F_api%2FMicrosoft.SharePoint.Utilities.WebTemplateExtensions.SiteScriptUtility.CreateSiteScript(Title%3D'%3CSITE%20script%3D%22%22%20title%3D%22%22%20name%3D%22%22%3E')%3C%2FSITE%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EHeaders%3CBR%20%2F%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%7B%0A%20%20%22Content-Type%5Cn%22%3A%20%22application%2Fjson%3Bcharset%3Dutf-8%22%2C%0A%20%20%22accept%22%3A%20%22application%2Fjson%3Bodata.metadata%3Dminimal%22%2C%0A%20%20%22odata-version%22%3A%20%224.0%22%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EBody%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%40%7Bvariables('SiteScript')%7D%20%2F%2F%20Reference%20of%20variable%20that%20we%20Initialized%26nbsp%3Bbefore%20this%20action.%3CBR%20%2F%3EGet%20Create%20Script%20ID%20and%20store%20it%20in%20Variable%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Dips365_1-1630571668730.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F307575i56504BB4A6E34C9E%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Dips365_1-1630571668730.png%22%20alt%3D%22Dips365_1-1630571668730.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ECreate%20Site%20Template%20using%20REST%20Call%20in%20Power%20Automate%3CBR%20%2F%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Dips365_0-1630571387332.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F307570i341D3D475CC54EEA%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Dips365_0-1630571387332.png%22%20alt%3D%22Dips365_0-1630571387332.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EParameters%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3ESite%20Address%20-%26nbsp%3BYou%20can%20select%20any%20site%20Address%20either%20it's%20root%20or%20not%3CBR%20%2F%3EMethod%20-%26nbsp%3Bpost%3CBR%20%2F%3EUrl%20-%20%2F_api%2FMicrosoft.SharePoint.Utilities.WebTemplateExtensions.SiteScriptUtility.CreateSiteDesign%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EHeaders%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%7B%0A%20%20%22Content-Type%5Cn%22%3A%20%22application%2Fjson%3Bcharset%3Dutf-8%22%2C%0A%20%20%22accept%22%3A%20%22application%2Fjson%3Bodata.metadata%3Dminimal%22%2C%0A%20%20%22odata-version%22%3A%20%224.0%22%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CSTRONG%3EBody%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%7B%0A%20%20%20%20%22info%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22Title%22%3A%20%22%3CSITE%20template%3D%22%22%20title%3D%22%22%3E%22%2C%0A%20%20%20%20%20%20%20%20%22Description%22%3A%20%22%3CSITE%20template%3D%22%22%20description%3D%22%22%3E%22%2C%0A%20%20%20%20%20%20%20%20%22SiteScriptIds%22%3A%20%5B%22%40%7Bvariables('ScriptID')%7D%22%5D%2C%0A%20%20%20%20%20%20%20%20%22WebTemplate%22%3A%20%2264%22%0A%20%20%20%20%7D%0A%7D%3C%2FSITE%3E%3C%2FSITE%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%3EThe%20flow%20looks%20like%20as%20below%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Flow6.jpg%22%20style%3D%22width%3A%20561px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F307573i8CF59854ED4EF893%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Flow6.jpg%22%20alt%3D%22Flow6.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EOutput%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EClick%20on%20the%20%E2%80%9Cgear%E2%80%9D%20Icon%20in%20SharePoint%20Site.%3C%2FP%3E%0A%3CP%3EClick%20on%20%E2%80%9CApply%20a%20site%20template%E2%80%9D.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Site%20Script%20and%20Site%20Template%20In%20Power%20Automate7.gif%22%20style%3D%22width%3A%20850px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F307574iEE56AB2CF6CB9535%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Site%20Script%20and%20Site%20Template%20In%20Power%20Automate7.gif%22%20alt%3D%22Site%20Script%20and%20Site%20Template%20In%20Power%20Automate7.gif%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2710696%22%20slang%3D%22en-US%22%3E%3CP%3ECreate%20Site%20Design%20and%20Site%20Template%20Using%20Power%20Automate%20in%20Modern%20SharePoint%20using%20Rest%20API%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2710696%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EHow%20to%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Co-Authors
Version history
Last update:
‎Sep 07 2021 03:46 AM
Updated by: