Use Power Automate to deploy a SharePoint site and lists

Back in the day, you could save a SharePoint site as a template (or solution) and deploy it elsewhere. Nowadays, it’s not quite so easy.

In this post, we’ll show you how to use Power Automate to make a REST API call and create a site and add a new list. This a great way for admins to manage request for new sites.

The master list

First of all, create list in a team site. This list will be used to trigger the flow and create the site and list.

The flow

Next, create a flow from the Automate button. The trigger will be ‘Complete a custom action for the selected item’

Then initialise a variable, like so

Next, we’ll make an API call to SharePoint and create our new site

Here’s the header and body code for you to copy:

{
  "Accept": "application/json;odata=verbose",
  "Content-Type": "application/json;odata=verbose;charset=utf-8"
}
{
"request": {
  "__metadata": { "type": "Microsoft.SharePoint.Portal.SPSiteCreationRequest"},
"WebTemplate": "STS#3",
"Title": "@{body('Get_item')['Title']}",
"Url": "@{variables('SiteURL')}",
"Description": "@{outputs('Get_item')?['body/Description']}",
"Classification": "",
"SiteDesignId": "00000000-0000-0000-0000-000000000000",
"Lcid": 1033,
"ShareByEmailEnabled": false,
"WebTemplateExtensionId": "00000000-0000-0000-0000-000000000000",
"Owner": "i:0#.f|membership|you@yourdomain.com",
"HubSiteId": "00000000-0000-0000-0000-000000000000"
}
}

#Be sure to change the email address for "Owner"

Creating the list

The first step is to create the list. This can be done by inserting a SharePoint HTTP Request Action in your Flow and setting it up like so:

Figure 1 – Create List Action in Power Automate

You’ll want to update the Title and Description properties and fill those in with the name and description of your list. The “BaseTemplate” property is what determines the type of list you’re creating. 100 is a blank list and 101 is a document library.

Creating Fields in the List

Once you create the list you need to add additional SharePoint HTTP Actions to create each field that you need to add in the list. That action will look like this:

Figure 2 – Create Field Action in Power Automate

In the URI input you’ll want to make sure you replace the “getbytitle(‘Name of your list’) with the name of the list you want to add your field to. The body of the action will vary based on the type of field you want to create. For quick reference, I have provided a table with the most common column types and the associated body code needed for the Power Automate action below:

Column TypePower Automate Code
Single Line of Text{
‘__metadata’: {‘type’:’SP.FieldText’, ‘addToDefaultView’: ‘true’ },
‘FieldTypeKind’: 2,
‘Title’: ‘Name of Single Line of Text Field’
}
Multi Line of Text{
‘__metadata’: {‘type’:’SP.Field’, ‘addToDefaultView’: ‘true’ },
‘FieldTypeKind’: 3,
‘Title’: ‘Name of Multi Line of Text Field’
}
DateTime{
‘__metadata’: {‘type’:’SP.FieldDateTime’, ‘addToDefaultView’: ‘true’ },
‘FieldTypeKind’: 4,
‘Title’: ‘Name of DateTime Field’,
‘DisplayFormat’: 0
}
Boolean (Yes/No){
‘__metadata’: {‘type’:’SP.Field’, ‘addToDefaultView’: ‘true’ },
‘FieldTypeKind’: 8,
‘Title’: ‘Name of Yes No Field’
}
Choice{ ‘__metadata’:
{ ‘type’: ‘SP.FieldChoice’, ‘addToDefaultView’: ‘true’ },
‘Title’: ‘Name of Choice Field’,
‘FieldTypeKind’: 6,
‘Required’: ‘true’,
‘Choices’: { ‘results’: [‘Choice 1’, ‘Choice 2’, ‘Choice 3’ ] }
}
Hyperlink{
‘__metadata’: {‘type’:’SP.Field’, ‘addToDefaultView’: ‘true’ },
‘FieldTypeKind’: 11,
‘Title’: ‘Name of Hyperlink Field’
}
Number{
‘__metadata’: {‘type’:’SP.FieldNumber’},
‘FieldTypeKind’: 1,
‘Title’: ‘Name of Number Field’
}
Person/Group{
‘__metadata’: {‘type’:’SP.Field’, ‘addToDefaultView’: ‘true’ },
‘FieldTypeKind’: 20,
‘Title’: ‘Name of Person or Group Field’
}

Figure 3 – SharePoint REST API Column Types

Add the Columns to the Default View

This next step is optional. If you want to make sure that the fields you just created show up in the default view of the list then you need to perform a couple more actions in your Flow. First, you’ll need an initialize variable action which will store an array of all of the column names you want to add like so:

Figure 4 – Configure the Column Names Variable

Once you have that, you need an Apply to Each action and within that you’ll make one final SharePoint HTTP action which will take those columns and add them to the default view like so:

Figure 5 – Add the Columns to the View

No Responses

Leave a Reply

Your email address will not be published. Required fields are marked *