Skip to content

Issues creating site script with SharePoint REST API #6944

@carolinedpena

Description

@carolinedpena

What type of issue is this?

Documentation issue / typo

What SharePoint development model, framework, SDK or API is this about?

SharePoint REST API

Target SharePoint environment

SharePoint Online

What browser(s) / client(s) have you tested

  • 💥 Internet Explorer
  • 💥 Microsoft Edge
  • 💥 Google Chrome
  • 💥 FireFox
  • 💥 Safari
  • mobile (iOS/iPadOS)
  • mobile (Android)
  • not applicable
  • other (enter in the "Additional environment details" area below)

Additional environment details

  • browser version
  • SPFx version
  • Node.js version
  • etc

Issue description

I am attempting to create a site script using the SharePoint REST API endpoint (/_api/Microsoft.SharePoint.Utilities.WebTemplateExtensions.SiteScriptUtility.CreateSiteScript) but I am continuously getting a 400 error with the message "The server encountered an error processing the request. See server logs for more details." I am closely following the documentation (https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/site-design-rest-api). I am using the sp-request library to call the API and have had no issues with getting site designs on my tenant or deploying updates to site designs. It seems to be an issue with the endpoint. Below is my code:

`
const siteScript = {
"$schema": "https://developer.microsoft.com/json-schemas/sp/site-design-script-actions.schema.json",
"actions": [
{
"locale": 1033,
"verb": "setRegionalSettings"
},
{
"group": "Owners",
"principal": "ContosoAdmins",
"verb": "addPrincipalToSPGroup"
}
],
"bindata": {},
"version": 1
};

const spr = sprequest.create({
    username,
    password
})

spr.post(url + "/_api/contextinfo")
.then(response => {
    digestValue = response.body.d.GetContextWebInformation.FormDigestValue
    return digestValue
})
.then(digest => {
    spr.post(url + `/_api/Microsoft.SharePoint.Utilities.WebTemplateExtensions.SiteScriptUtility.CreateSiteScript(Title=@title)?@title='Test'`, {
        headers: {
            "Content-Type": "application/json;charset=utf-8",
            "X-RequestDigest": digest,
            "ODATA-VERSION": "4.0"
        },
        body: {
            "info": {
                "Content": JSON.stringify(siteScript)
            }
        }
    }).catch(err => console.log(err))
})`

Is the issue with the formatting of the body?

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:csom/rest/apiCategory: SharePoint Client Side Object Model SDK / REST APIarea:site-designCategory: Site Designs/Site Scriptstype:archive-old-issueIssues which are closed as tool old for active worktype:questionQuestion... if answered, will be tagged as such.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions