I know this can be done using the JSOM, but is it possible via the REST API to create a document set?
-
Great question, Robert!Vadim Gremyachev– Vadim Gremyachev2014-09-12 07:01:13 +00:00Commented Sep 12, 2014 at 7:01
-
Thanks Vadim. I know it must be if the JSOM can do it. I'm hoping to be able to avoid using Fiddler or similar to figure it out. But it looks like I may have to.Robert Kaucher– Robert Kaucher2014-09-12 13:19:30 +00:00Commented Sep 12, 2014 at 13:19
-
So you had created document set using rest api? I know its an old post but still curious to know the answer. If not, have you tried to include property 'ContentTypeId':'DocumentSetId' in metadata while making ajax request? Maybe that work for you?ateet– ateet2014-09-20 16:23:12 +00:00Commented Sep 20, 2014 at 16:23
-
I've not tried yet. Going to use JSOM and see what it calls on the backend. Then I'll update this with an answer.Robert Kaucher– Robert Kaucher2014-09-20 22:00:07 +00:00Commented Sep 20, 2014 at 22:00
Add a comment
|
1 Answer
How to create a Document Set using SharePoint REST Interface
The following example demonstrates how to create a Document Set in SharePoint 2013:
function getListUrl(webUrl,listName,success, error)
{
var headers = {};
$.ajax({
url: webUrl + "/_api/lists/getbytitle('" + listName + "')/rootFolder?$select=ServerRelativeUrl",
type: "GET",
contentType: "application/json;odata=verbose",
headers: {
"Accept": "application/json;odata=verbose"
},
success: function(data){
success(data.d.ServerRelativeUrl);
},
error: error
});
}
function createFolder(webUrl,listName,folderName,folderContentTypeId, success, error)
{
getListUrl(webUrl,listName,
function(listUrl) {
var folderPayload = {
'Title' : folderName,
'Path' : listUrl
};
//Create Folder resource
$.ajax({
url: webUrl + "/_vti_bin/listdata.svc/" + listName,
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify(folderPayload),
headers: {
"Accept": "application/json;odata=verbose",
"Slug": listUrl + "/" + folderName + "|" + folderContentTypeId
},
success: function (data) {
success(data.d);
},
error: error
});
},
error);
}
function createDocumentSet(webUrl,listName,folderName, success, error)
{
createFolder(webUrl,listName,folderName,'0x0120D520', success, error);
}
Comments:
getListUrlfunction is used for retrieving List/Library UrlWith some modifications applied (in fact it concerns
getListUrlfunction only) it could be used in SharePoint 2010
Example
Create Document Set named Orders in Documents library:
createDocumentSet(_spPageContextInfo.webAbsoluteUrl,'Documents','Orders',
function(folder){
console.log('Document Set ' + folder.Name + ' has been created succesfully');
},
function(error){
console.log(JSON.stringify(error));
}
);
-
1Thank you! I was able to use this example to make a web service call from within a SharePoint Designer WorkFlow!! The "Slug" was a key factor!!!! So happy...Jason Young– Jason Young2014-10-08 20:43:24 +00:00Commented Oct 8, 2014 at 20:43
-
1Thanks, Vadim. Even though this uses
ListData.svcand not_API, it was exactly what we needed.Robert Kaucher– Robert Kaucher2014-10-10 13:12:54 +00:00Commented Oct 10, 2014 at 13:12 -
It seems to ignore the folderPayload setting, is it possible at all to set metadata on creation?? I have a custom sitecolumn with a validation rule which causes an error on creation, if I remove the validation rule everything works fin.Danny '365CSI' Engelman– Danny '365CSI' Engelman2015-04-04 15:12:50 +00:00Commented Apr 4, 2015 at 15:12
-
@Vadim Does this still work? When I run this code I get a 500 Internal Server error that just says "An error occurred while processing this request.James11– James112015-11-05 16:50:10 +00:00Commented Nov 5, 2015 at 16:50
-
@James11, hm, it works for me, is Document Set content type is added into library?Vadim Gremyachev– Vadim Gremyachev2015-11-05 17:26:56 +00:00Commented Nov 5, 2015 at 17:26