Is it possible to create a project documentset using graph API?

1.8k views Asked by At

So far I haven't been able to find any information on how to create project documentsets on my Sharepoint environment using the Graph API. I've tried both Sharepoint's 'Create item' and OneDrive's 'Create Folder'. The Sharepoint API says:

"Files and folders should only be added to a DocumentLibrary via the OneDrive API"

The OneDrive API says:

"Either 'folder' or 'file' must be provided, but not both."

As you can tell from the responses, it seems limited to only having the options to create either a folder or a file. Is this correct? Is there any way to mutate a folder to a document set using a different API call?

I have tried to add the content type ID to the different request bodies, in every case providing no further solution.

Hope someone here knows a possible solution and can help me. Thanks!

2

There are 2 answers

0
R.Schouten On

I have been looking into this myself aswell and walked into the same wall. At the moment, unfortunately, there is no combined method. You can use them both to combine it to your own documentset.

Kind regards, R Schouten

1
Andres Biarge On

I've dealt with the same issue today. I needed to create a Document Set in the root level of a Document Library after some business logic.

Here's how I've achieved to do so:

1- Get the document library's Drive Id:

GET https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${listId}?$expand=drive

2- Create the folder:

POST https://graph.microsoft.com/v1.0/drives/${library.drive.id}/root/children

Remember to set the body as:

{
    "name": ${nameOfTheFolder},
    "folder": {},
}

3- Get the folder's SharePoint item id:

GET https://graph.microsoft.com/v1.0/sites/${siteId}/drives/${library.drive.id}/items/${folder.id}?expand=sharepointids 

4- Update the item in the Document Library so that it updates to the desired Document Set:

PATCH https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${listId}/items/${sharepointIds.listItemId}

Don't forget to set the body to:

{
  "contentType": {
    "id": "content-type-id-of-the-document-set"
  },
  "fields": {
    //whatever fields you want to set
  }
}

Hope it helps