Invoking a Site Design Task using REST

Site designs provide the ability for the provisioning of assets during the site creation process in Modern SharePoint. The site design documentation is fairly robust and includes commands to interact with site designs using PowerShell and REST. Recently, there have been updates to Site Designs and the documentation is still playing catch up.

One of the latest releases includes the ability to invoke more than 30 actions in a site script. I’ve talked about this extensively in my previous post. This post includes the methods for executing a site design using PowerShell. Today, we’ll talk about the options of using REST.

ApplySiteDesign (old way!)

ApplySiteDesign was the original REST endpoint for applying a site design to an existing site collection. This would allow you create a POST request to the ApplySiteDesign endpoint and pass in the SiteDesignId and the WebUrl to the body.

This invocation is limited to the 30 actions in a site script.

Request

fetch("https://testsite.sharepoint.com/sites/test/_api/Microsoft.Sharepoint.Utilities.WebTemplateExtensions.SiteScriptUtility.ApplySiteDesign", {
    "credentials": "include",
    "headers": {
        "accept": "application/json;odata=verbose",
        "accept-language": "en-US,en;q=0.9",
        "content-type": "application/json;odata=verbose",
        "x-requestdigest": "YourXRequestDigest"
    },
    "referrer": "https://testsite.sharepoint.com/sites/test",
    "referrerPolicy": "no-referrer-when-downgrade",
    "body": "{\"siteDesignId\":\"38ef12db-e8b8-4716-96d9-7556c61bf98b\",\"webUrl\":\"https://testsite.sharepoint.com/sites/test\"}",
    "method": "POST",
    "mode": "cors"
});

AddSiteDesignTaskToCurrentWeb  (new way!)

AddSiteDesignTaskToCurrentWeb is the new REST endpoint for site designs, which provides the ability to overcome the 30 action limit. This new endpoint now allows for 300 actions or 100k characters in a site script (or cumulative across all site scripts in a given Site Design). The only parameters required to execute a site design task is to pass in the site design using the siteDesignId property.

Request

fetch("https://testsite.sharepoint.com/sites/test/_api/Microsoft.Sharepoint.Utilities.WebTemplateExtensions.SiteScriptUtility.AddSiteDesignTaskToCurrentWeb", {
    "credentials": "include",
    "headers": {
        "accept": "application/json;odata=verbose",
        "accept-language": "en-US,en;q=0.9",
        "content-type": "application/json;odata=verbose",
        "x-requestdigest": "YourXRequestDigest"
    },
    "referrer": "https://testsite.sharepoint.com/sites/test",
    "referrerPolicy": "no-referrer-when-downgrade",
    "body": "{\"siteDesignId\":\"38ef12db-e8b8-4716-96d9-7556c61bf98b\"}",
    "method": "POST",
    "mode": "cors"
});

Response

{
    "d": {
        "AddSiteDesignTaskToCurrentWeb": {
            "__metadata": {
                "type": "Microsoft.SharePoint.Utilities.WebTemplateExtensions.SiteDesignTask"
            },
            "ID": "b86f5a1c-c153-4ff9-b17f-c9c123ee9249",
            "LogonName": "i:0#.f|membership|beau@cameronsoft.onmicrosoft.com",
            "SiteDesignID": "38ef12db-e8b8-4716-96d9-7556c61bf98b",
            "SiteID": "2636e586-47e2-4644-9b01-88f73b397e9e",
            "WebID": "7ccf233e-97e6-46bc-9101-3607e1b221ba"
        }
    }
}

If you’d like to see which site designs have been applied to this site or want to see the success of each action within this invocation, you can follow this post which shows examples using REST and PowerShell.

Have really long site scripts?

What happens if you have site scripts that are over 300 actions, and the current framework will not support it? A tip  is to break the site scripts out into multiple site designs and call them via flow. Check out Reza Dorrani’s blog showing how to do this.

8 thoughts on “Invoking a Site Design Task using REST

    • Beau Cameron October 19, 2020 / 9:27 am

      Hi! Not a problem. The issue is your JSON is invalid, you are missing a double quote. You need to have a closing double quote around siteDesignId. “siteDesignId”: not “siteDesignId:

      Thanks!

      Liked by 1 person

      • Saulo Oliveira October 19, 2020 / 9:54 am

        Hi Beau, sorry about that. I adjusted it and now when trying to run I get the following error: Cannot convert a primitive value to the expected type ‘Edm.Guid’. Any idea?

        Like

      • Beau Cameron October 19, 2020 / 3:25 pm

        Seems like it’s having issues accepting the values for your guid. It’s hard to say, when I look at the API being used, it may have changed since my original blog post… and includes another parameter called “store”, which I don’t know how that works…

        Liked by 1 person

      • Saulo Oliveira October 19, 2020 / 5:25 pm

        No problem Beau, thanks for your support. If I get the solution I’ll share it here, thanks.

        Like

  1. Steve B February 17, 2021 / 2:15 am

    thanks for this article

    Regarding the limits, you said a sitescript can contains up to 300 actions and 100K chars. To overcome this, you suggest to split it into multiple site designs.

    But a site design isn’t limited to a single site script. What about splitting a site script into mulitple ones, but all attached to a single site design ? Will the limits apply per script or per design ?

    Like

    • Beau Cameron February 17, 2021 / 8:01 am

      Unfortunately it’s cumulative across all site scripts that are part of a site design. A site design in total can only have 300 actions or 100k characters whether it contains 1 site script or 5 Site Scripts.

      I can clarify the post a bit more to make this point. This is why the reference I have at the bottom, is actually calling multiple Site Designs… if you need more than 300 actions.

      Like

Leave a comment