Create new SharePoint list from existing SP list with Power Automate

“I need to create the same SharePoint list with multiple columns on various SP sites, can Power Automate use SP list as a template? Or do I need build it from scratch column after column?”


If you use Power Automate to create SharePoint list(s), you probably use multiple HTTP requests. One HTTP request to create the list, and then separate HTTP requests for each column in the list, as described for example in this blog post. But I believe there’s an easier way utilising the OOTB SharePoint functionality to create a new list from an existing one.

When you create a ‘template’ SP list, you don’t need to bother with any code. You can use the SharePoint interface to define all the columns, their type and format, list views… and then you manually create new list from the ‘template’…

…or you can use Power Automate to do it for you. If you open the console in your browser during the manual process, you can track what’s happening. Among all the requests are 2 API calls responsible for the list creation.

_api/Microsoft.Sharepoint.Utilities.WebTemplateExtensions.SiteScriptUtility.GetSiteScriptFromList()

_api/Microsoft.Sharepoint.Utilities.WebTemplateExtensions.SiteScriptUtility.ExecuteTemplateScript()

The first request will get all the information about the source list. The second one will use it to create a new list. If you replicate these two calls from your flow, you can create a new SP list from an existing one.

GetSiteScriptFromList()

As already mentioned, the first HTTP request will get the SharePoint list structure. Here it doesn’t matter what ‘Site Address’ you use as long as it’s in your environment (but the listUrl matters!).

Method: POST

Uri: _api/Microsoft.Sharepoint.Utilities.WebTemplateExtensions.SiteScriptUtility.GetSiteScriptFromList()

Headers:
accept : application/json;odata=verbose
content-type : application/json;odata=verbose

Body:
{
  "listUrl": "https://<xxx>.sharepoint.com/sites/<SourceSiteName>/Lists/<SourceListName>/"
}

Note: everything inside < .. > is a placeholder, you should replace it including the < and >.

Power Automate get SharePoint list schema

The output of this HTTP request will be a hard-to-read JSON schema of the source list, and potentially also source for the ‘lookup’ lists.

SharePoint list schema

Parse the output

Now you’ve got the JSON and it’s time to prepare it for the second HTTP request with the ‘Parse JSON’ action. To save a few actions, you can access directly the ‘GetSiteScriptFromList’ value in the JSON. That’s where all the list information is stored.

outputs('<HTTPrequestActionName>')?['body']?['d']?['GetSiteScriptFromList']

e.g.
outputs('Send_an_HTTP_request_to_SharePoint_-_get_list_structure')?['body']?['d']?['GetSiteScriptFromList']

Use the whole output from the previous HTTP request as the sample payload for ‘Parse JSON’.

Power Automate parse SharePoint list schema

The output from such ‘Parse JSON’ will be the same JSON, this time in a more readable format, but still far away from the required format for the second request.

ExecuteTemplateScript()

For the second HTTP request body you must enclose only the “actions” object from the JSON above in a ‘{“script”:’ element.

{"script": "{\"actions\": [....] }" }

Unfortunately, the output has one extra element “$schema”. You’re not interested in that one, you need only the “actions”, the “$schema” must be removed. That’s why you need the ‘Parse JSON’, to allow you to select only the “actions”.

body('Parse_JSON')?['actions']

And with that it’s time to build the whole request body. You’ve got the value from “actions”, now you must add back the “actions” element and enclose it in a “script”. You must also turn this nice request into the less-readable original form by replacing \ with \\ and ” with \”.

This time also the ‘Site Address’ matters, it’s the target site for the new list.

Method: POST

Uri: _api/Microsoft.Sharepoint.Utilities.WebTemplateExtensions.SiteScriptUtility.ExecuteTemplateScript()

Headers:
accept : application/json;odata=verbose
content-type : application/json;odata=verbose

Body:
{"script": "{\"actions\":@{replace(replace(string(body('Parse_JSON')?['actions']),'\','\\'),'"','\"')}}"}
Power Automate create SharePoint list from existing one

Summary

You’ve got multiple options how to create a new SharePoint list with Power Automate. You can either define all the requests for all the columns by yourself, or you can let SharePoint do the work. My preference goes to the 3 actions above. Create the list in SharePoint, get its schema, process it a bit, and use it to create a new list. And if needed, you can add it also to the site navigation.

You can use the same approach also to move lists between different environments. Export the list using the first HTTP request, store the output in a text editor, and then use it as the input on the other environment. Just keep in mind that you’re copying only the list structure, not the list data.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

17 Comments

Add a Comment

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