Forum Discussion

Nigel Witherdin's avatar
Nigel Witherdin
Iron Contributor
Feb 10, 2020

How to create and change a folder's content type using the MS Graph API

Hi,

I need to create a folder using the Graph API, then change its content type and set metadata against it.

Ideally I would like to use SharePoint end points (/site/) to:

- Create the folder in a specific library

- Change the folders content type to a custom one

- Update metadata on the folder

 

Can anyone please provide me an example of doing this?

 

Many thanks!

    • Create the folder: 

      POST /drives/{drive-id}/items/root/children

      {

      "name": "{name}",

      "folder": { },

      "@microsoft.graph.conflictBehavior": "fail"

      }

    • Get the created folder's item id: 
      GET /drives/{drive-id}/items/root:/{folder-name}?expand=sharepointIds
    • Update folder's content type and metadata:

      PATCH /sites/{site-id}/lists/{library-name}/items/{item-id}

      {

      "contentType":

        {

          "id": "{content-type-id}"

        },

      "fields":

        {

        "field_1_name": "{field_1_value}",

        "field_2_name": "{field_2_value}"

        }

      }

    • Create the folder: 

      POST /drives/{drive-id}/items/root/children

      {

      "name": "{name}",

      "folder": { },

      "@microsoft.graph.conflictBehavior": "fail"

      }

    • Get the created folder's item id: 
      GET /drives/{drive-id}/items/root:/{folder-name}?expand=sharepointIds
    • Update folder's content type and metadata:

      PATCH /sites/{site-id}/lists/{library-name}/items/{item-id}

      {

      "contentType":

        {

          "id": "{content-type-id}"

        },

      "fields":

        {

        "field_1_name": "{field_1_value}",

        "field_2_name": "{field_2_value}"

        }

      }

Resources