Forum Discussion

Ross McLean's avatar
Ross McLean
Copper Contributor
Jan 16, 2017
Solved

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...
  • Clint Lechner's avatar
    Clint Lechner
    Jan 17, 2017
    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));
    }
    );

Resources