David Mason
David Mason

Reputation: 329

Create document set with REST in SharePoint Online

I am struggling with the creation of a document set via REST API in SharePoint online. The only solution I found doing this was using the old SharePoint 2010 REST interface in the following way:

$http({
  method: "POST",
  url: url + "/_vti_bin/listdata.svc/" + listTitle,
  data: JSON.stringify(docSetOptions),
  headers: {
    "Accept": "application/json;odata=verbose",
    "content-type": "application/json;odata=verbose",
    "X-RequestDigest": $('#__REQUESTDIGEST').val(),
    "Slug": _spPageContextInfo.siteServerRelativeUrl + "/" + url + docSetOptions.Path + "/" + docSetOptions.Title + "|" + docSetOptions.ContentTypeId,
  }
}).success(function (data, status, headers, config) {
  logtoconsole("document set created");
}).error(function (data, status, headers, config) {
  logtoconsole("document set error");
});

docSetOptions are those:

            var folder = new
            {
                Title = "foo",
                Path = "foo",
                ContentTypeId = "0x010050D9126DC6276846BF6D869EF2090EAD",
                ContentType = "SP.Data.Shared_x0020_DocumentsItem",
            };

The id is the id of my custom content type, derived from document set.

Source: http://www.itidea.nl/index.php/create-a-document-set-using-jsom-and-rest/

This works for me, but a regular folder is created. No document set. Does anybody know if this still works in SharePoint Online? The only entries I found were regarding SharePoint 2013.

Update: I ran the same script against my SharePoint 2013 on Premise Server and it works perfectly. Document set is created. Microsoft changed this a few months ago. It used to be possible!

Upvotes: 1

Views: 4116

Answers (1)

David Mason
David Mason

Reputation: 329

Okay, I found a solution. Since a while it is not possible anymore, to create a document set via REST if the sites content type id is used. In my case, I had to use the id of the content type in the library. So I went to my library settings, selected my content type and copied it. The id differs a little. In my case was 0x0120D5200085474276CB6D314E9BC0E6F067D47DBE. But in your case it will look different. If I use this id my document set is created successfully! This took me hours to find out.

Upvotes: 1

Related Questions