SOLVED

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

%3CLINGO-SUB%20id%3D%22lingo-sub-1163366%22%20slang%3D%22en-US%22%3EHow%20to%20create%20and%20change%20a%20folder's%20content%20type%20using%20the%20MS%20Graph%20API%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1163366%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EI%20need%20to%20create%20a%20folder%20using%20the%20Graph%20API%2C%20then%20change%20its%20content%20type%20and%20set%20metadata%20against%20it.%3C%2FP%3E%3CP%3EIdeally%20I%20would%20like%20to%20use%20SharePoint%20end%20points%20(%2Fsite%2F)%20to%3A%3C%2FP%3E%3CP%3E-%20Create%20the%20folder%20in%20a%20specific%20library%3C%2FP%3E%3CP%3E-%20Change%20the%20folders%20content%20type%20to%20a%20custom%20one%3C%2FP%3E%3CP%3E-%20Update%20metadata%20on%20the%20folder%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECan%20anyone%20please%20provide%20me%20an%20example%20of%20doing%20this%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMany%20thanks!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1176724%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20create%20and%20change%20a%20folder's%20content%20type%20using%20the%20MS%20Graph%20API%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1176724%22%20slang%3D%22en-US%22%3E%3CUL%3E%3CLI%3ECreate%20the%20folder%3A%26nbsp%3B%3CP%3EPOST%20%2Fdrives%2F%7Bdrive-id%7D%2Fitems%2Froot%2Fchildren%3C%2FP%3E%3CP%3E%7B%3C%2FP%3E%3CP%3E%22name%22%3A%20%22%7Bname%7D%22%2C%3C%2FP%3E%3CP%3E%22folder%22%3A%20%7B%20%7D%2C%3C%2FP%3E%3CP%3E%22%40microsoft.graph.conflictBehavior%22%3A%20%22fail%22%3C%2FP%3E%3CP%3E%7D%3C%2FP%3E%3C%2FLI%3E%3CLI%3EGet%20the%20created%20folder's%20item%20id%3A%26nbsp%3B%3CBR%20%2F%3EGET%20%2Fdrives%2F%7Bdrive-id%7D%2Fitems%2Froot%3A%2F%7Bfolder-name%7D%3Fexpand%3DsharepointIds%3C%2FLI%3E%3CLI%3EUpdate%20folder's%20content%20type%20and%20metadata%3A%3CBR%20%2F%3E%3CP%3EPATCH%20%2Fsites%2F%7Bsite-id%7D%2Flists%2F%7Blibrary-name%7D%2Fitems%2F%7Bitem-id%7D%3C%2FP%3E%3CP%3E%7B%3C%2FP%3E%3CP%3E%22contentType%22%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%20%7B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%22id%22%3A%20%22%7Bcontent-type-id%7D%22%3C%2FP%3E%3CP%3E%26nbsp%3B%20%7D%2C%3C%2FP%3E%3CP%3E%22fields%22%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%20%7B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%22field_1_name%22%3A%20%22%7Bfield_1_value%7D%22%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%20%22field_2_name%22%3A%20%22%7Bfield_2_value%7D%22%3C%2FP%3E%3CP%3E%26nbsp%3B%20%7D%3C%2FP%3E%3CP%3E%7D%3C%2FP%3E%3C%2FLI%3E%3C%2FUL%3E%3C%2FLINGO-BODY%3E
Highlighted
Contributor

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!

1 Reply
Highlighted
Solution
  • 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}"

      }

    }