Get site script from list using REST

New updates from Microsoft for site scripts and site designs really improved the creation of the JSON required in a site script. One of the newest features is the ability to generate a site script from an existing list. If you have seen my previous post on creating managed metadata fields using site scripts, you’d quickly learn how tedious and complex JSON can be.

Thankfully, there is a new process that allows you to generate the site script syntax from an existing list in your SharePoint environment, making it much easier to construct these site scripts. The current documented method for doing this is by using a PowerShell command called Get-SPOSiteScriptFromList.

There is another method for achieving this and it’s by using the REST api. Currently, this endpoint is not documented,  but I have submitted a PR in the documentation to correct this.


GetSiteScriptFromList is a new endpoint that allows you to generate the syntax required for a site script from an already created list.


ParametersPass in a listUrl parameter with the url to the list you want to create the site script syntax for.

fetch("", {
    "credentials": "include",
    "headers": {
        "accept": "application/json;odata=verbose",
        "accept-language": "en-US,en;q=0.9",
        "content-type": "application/json;odata=verbose",
        "x-requestdigest": "YourRequestDigest"
    "referrer": "",
    "referrerPolicy": "no-referrer-when-downgrade",
    "body": "{\"listUrl\":\"\"}",
    "method": "POST",
    "mode": "cors"


The response contains an array of actions for creating this list.  The command supports most field types, including complex field types such as managed metadata columns.

  "actions": [
      "verb": "createSPList",
      "listName": "Contoso customer list",
      "templateType": 100,
      "subactions": [
          "verb": "addSPView",
          "name": "All Items",
          "viewFields": [
          "query": "",
          "rowLimit": 30,
          "isPaged": true,
          "makeDefault": true
      "verb": "addNavLink",
      "url": "Lists/Contoso customer list/AllItems.aspx",
      "displayName": "Contoso customer list",
      "isWebRelative": true

Now what?

Now that we have the syntax to create the list, we can just add the values from the actions array to a new or existing site script. For information on how to create a site script, follow the documentation here.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s