Forum Discussion
Ross McLean
Jan 16, 2017Copper Contributor
Creating a Document Set with the Sharepoint 2013 REST API
Is there (or does anyone at Microsoft know if there will be) support for creating Document Sets using the 2013 version of the REST API? I've successfully used the 2010 /_vti_bin/listdata.svc/ servic...
- Jan 17, 2017function 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);
}
createDocumentSet(_spPageContextInfo.webAbsoluteUrl,'Documents','Orders',
function(folder){
console.log('Document Set ' + folder.Name + ' has been created succesfully');
},
function(error){
console.log(JSON.stringify(error));
}
);
Ross McLean
Jan 16, 2017Copper Contributor
Hi Kushan, thanks for the reply. Using the /_api/Web/Folders/add I can create a standard folder. I can then use the endpoint /_api/Web/Lists/GetByTitle to modify the ContentTypeId to that of the Document set. The last piece of the puzzle seems to either be setting the ProgId to SharePoint.DocumentSet, or HTML_x0020_File_x0020_Type to SharePoint.DocumentSet, however both of these properties seems to resist being updated by REST.
Clint Lechner
Jan 17, 2017Iron Contributor
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);
}
createDocumentSet(_spPageContextInfo.webAbsoluteUrl,'Documents','Orders',
function(folder){
console.log('Document Set ' + folder.Name + ' has been created succesfully');
},
function(error){
console.log(JSON.stringify(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);
}
createDocumentSet(_spPageContextInfo.webAbsoluteUrl,'Documents','Orders',
function(folder){
console.log('Document Set ' + folder.Name + ' has been created succesfully');
},
function(error){
console.log(JSON.stringify(error));
}
);