I am trying to create a new folder inside a document library using JSOM, below is my code
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/folders";
function getFormDigest(webUrl) {
return $.ajax({
url: webUrl + "/_api/contextinfo",
method: "POST",
headers: { "Accept": "application/json; odata=verbose" }
});
}
$("#btnClick").click(function(){
return getFormDigest(_spPageContextInfo.webAbsoluteUrl).then(function (data) {
return $.ajax({
url: requestUri,
type: "POST",
data:JSON.stringify({'__metadata': { 'type': 'SP.Folder' }, 'ServerRelativeUrl': '/Documents/NewFoldername'}),
headers: {
"accept":"application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": data.d.GetContextWebInformation.FormDigestValue
},
success: onSuccess,
error: onError
});
function onSuccess(data) {
alert('Folder created successfully');
}
function onError(error) {
alert(JSON.stringify(error));
}
});
});
});
I am getting the below error
"{"readyState":4,"responseText":"{\"error\":{\"code\":\"-2147024809, System.ArgumentException\",\"message\":{\"lang\":\"en-US\",\"value\":\"Value does not fall within the expected range.\"}}}","responseJSON":{"error":{"code":"-2147024809, System.ArgumentException","message":{"lang":"en-US","value":"Value does not fall within the expected range."}}},"status":400,"statusText":"Bad Request"}"
/Documents/NewFoldername
is valid?