I'm trying to create a Folder in a SharePoint Image library. I found an answer here but I can't seem to get it to work
var web = 'my relative path to the current web';
var lib = 'name of the image library';
var foldername = 'jasonscript';
var postData = JSON.stringify({
'__metadata' : { 'type': 'SP.Folder' },
'ServerRelativeUrl' : lib + '/' + foldername
});
var pCreate = jQuery.ajax({
'url' : web + '/_api/Web/Folders',
'type' : 'POST',
'data' : postData,
'headers' : {
'accept' : 'application/json; odata=verbose',
'content-type' : 'application/json; odata=verbose',
'X-RequestDigest' : $('#__REQUESTDIGEST').val()
}
});
jQuery.when(pCreate).always(function (data){
console.log(data);
});
This returns the following error:
{
"error":{
"code":"-2130247139, Microsoft.SharePoint.SPException",
"message":{
"lang":"en-US",
"value":"(null) \"██████/██████/██████\" not found."
}
}
}
where the redacted values are the web, lib and foldername values.
I know the folder doesn't exist. I'm trying to create it!
Update
I'm trying to run this code in a Content Editor Web Part (i.e. Not an app)
Any ideas?