0

I implemented with Graph API several calls to create a document set. I followed the answer posted here concerning the possibility of creating a DocumentSet in SharePoint here : Is it possible to create a project documentset using graph API?

For this i followed those steps :

1. Getting the library driveId :

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

2. Creating the folder:

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

I have to pass an object:

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

3. Getting the Sharepoint itemId:

4. Updating the document library:

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

and passing a body:

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

I have questions concerning the folder creation and the updating: What is expected in the folder object ?

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

Concerning the path step:

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

I have several questions :

  • Let's consider i have a document type called invoices. Which id is expected for document type id ?
  • finally how do i pass the fields ? let's say i want to pass 3 fields : invoiceId, claimId, clientId.

Graph API is great but some more information would be helpful. thanks !

davidvera
  • 1,292
  • 2
  • 24
  • 55

3 Answers3

1

I have questions concerning the folder creation and the updating: What is expected in the folder object ?

The folder object (sent as {}) is there to tell graph API that you are creating a folder and not a file. It is a property of the drive item

Let's consider i have a document type called invoices. Which id is expected for document type id ? This is the id contentType subfield of the list item you are patching

ally how do i pass the fields ? let's say i want to pass 3 fields : invoiceId, claimId, clientId.

You just pass them with repective values like below. See Update listItem

{
   "invoiceId": "value",
   "claimId": "value"
   ...
}
Danstan
  • 1,501
  • 1
  • 13
  • 20
0

One point I didn't express correctly was to know what id is expected here :

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

I retrieved the different content types of my site by calling this kind of URL and check if the content type exists.

https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${listId}/contentTypes

From the result i retrieve in a Value object the id. The id looks like this :

0x0120D5200082903AB771604546844DB2AC483D905B00E58445A7D..........

davidvera
  • 1,292
  • 2
  • 24
  • 55
0

In modern SharePoint, you can also get the Content Type ID from the UI by browsing to SharePoint Site > Site Settings > Site content types > <ContentTypeName> > Content Type ID.

Content Type ID

Not sure if this is easier than via graph, but it's another option at least.

ouflak
  • 2,458
  • 10
  • 44
  • 49
David Adams
  • 83
  • 1
  • 1
  • 6