Sharepoint - Creating document set and setting values with REST/listdata.svc

The following example demonstrates how to create Document Set and set its properties:

function createFolder(webUrl,listName,folderOptions) 
{  
     var folderPayload = folderOptions; 
     folderPayload['Title'] = folderOptions.Url.split('/').pop();
     folderPayload['Path'] = folderOptions.Url.split('/').slice(0, -1).join('/');

     //Create Folder resource
     return $.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": folderOptions.Url + "|" + folderOptions.ContentTypeId
            }
      });
}


function createDocumentSet(webUrl,listName,docSetOptions)
{
    docSetOptions.ContentTypeId = '0x0120D520';
    return createFolder(webUrl,listName,docSetOptions);
}



function updateFolderProperties(folder,properties)
{
    return $.ajax({
         type: 'POST',
         url: folder.__metadata.uri,
         contentType: 'application/json',
         headers: {
                "Accept": "application/json;odata=verbose",
                "X-HTTP-Method": "MERGE",
                "If-Match": folder.__metadata.etag
         },
         data: JSON.stringify(properties),
   });
}

Usage

var webUrl = _spPageContextInfo.webAbsoluteUrl;
var listName = 'Documents';
var docSetOptions = { 
    'Url': '/Documents/Orders2015'
};
createDocumentSet(webUrl,listName,docSetOptions)
.then(function(data){
    var itemProperties = {
              'Description' : 'Orders 2015',
              'StartDate': '2015-06-23T07:00:00Z'
    };
    return updateFolderProperties(data.d,itemProperties)
})
.done(function(){
    console.log('Document Set has been created succesfully'); 
})
.fail(function(error){
    console.log(JSON.stringify(error));
});

Key points:

  1. The example consists of two requests: 1)create a Document Set 2)update Document Set associated ListItem properties
  2. updateFolderProperties function serves for updating Document Set properties
  3. It is assumed that DocumentSetDescription is a built-in Description field of Document Set content type