Issues creating site script with SharePoint REST API
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
- [X] 💥 Microsoft Edge
- [X] 💥 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?
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.
Thank you for taking the time to file an issue. We periodically archive older or inactive issues as part of our issue management process, which automatically closes them once they are archived.
If you’d like to understand more about why and how we handle archived (closed) issues, please see Our approach to closed issues.
We appreciate your contribution and if this is still an active issue with the latest SPFx versions, please do resubmit the details. We needed to perform a cleanup, so that we can start with a clean table with a new process. We apologize for the inconvenience this might cause.