MS GraphAPI Drives Create new folder

Viewed 504

I need help with Microsoft GraphAPI. I want to create folder in SharePoint Online Site Collection, in Document Library, but i get Error.

I Have Site Collection, name A, in this Site Collection i have Document Library, name XY I have tried to create Folder using this

POST /sites/{site-id}/drive/items/{parent-item-id}/children

https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_post_children?view=odsp-graph-online

But i always get error, 400 Bad Request.

.../v1.0/sites/tenantName,1a2b3f27-0d23-4b68-8e71-fe06cbfed6b4,5e911195-1934-42a3-814c-86ab8ec2699c/drive/items/b!Jz8rGiMNaEuOcf4Gy_7WtJURkV40GaNCgUyGq47CaZwdNH0_zurqQ6XWJreCPMnF/children";

Error message is, "The expression is not valid".

What am I doing wrong?

1 Answers

It seems that you are using driveId as the parent-item-id. The parent-item-id looks like 01KC572RLYVJZL5JE4ANCLOTQKQMIKYVHL

You can get the parent-item-id by using

GET /sites/{site-id}/drive/root/children

If you get nothing from this request, you should create a folder under the root directory first.

POST /sites/{site-id}/drive/root/children

{
  "name": "New Folder222",
  "folder": { },
  "@microsoft.graph.conflictBehavior": "rename"
}
Related