0

I can create a nested folder /folder1/folder2 in (personal) OneDrive with the following Graph request (using the beta API):

POST drives/{id}/root:/folder1:/children

{
  "name": "folder2",
  "folder": {},
  "@microsoft.graph.conflictBehavior": "fail"
}

Here, folder1 didn't exist beforehand; the one API call creates both it and folder1/folder2.

However, the same code fails for SharePoint and OneDrive for Business with a 404 error. Is this type of request supported? I'd rather not have to make a separate API call for every level of nesting.

I'm asking this because I'm not sure whether my site has policies that cause the request to fail, or because the API actually doesn't support it.

4
  • AFAIK, you should give the folder name(while giving path) or folder id(while giving id) of the parent folder to create a sub folder inside it, because the documentation should have the parent-item-id to create a folder. The only way is it make a separate API call for every level as you said. You can get the path property in the response when you create a folder, you can use it to automate calls easily. Commented Mar 15, 2021 at 4:22
  • @ShivaKeshavVarma the code above works for personal OneDrive; I've verified this Commented Mar 15, 2021 at 4:23
  • This is despite the docs not mentioning it Commented Mar 15, 2021 at 4:24
  • Yeah, I have also tested it in personal which worked but not with work account. Commented Mar 15, 2021 at 4:29

1 Answer 1

2
+100

This works for me. Remove name parameter from the body and use PATCH instead of POST. Specify the path in the URL.

PATCH drives/{id}/root:/folder1/folder2

{
    "folder": {},
    "@microsoft.graph.conflictBehavior": "fail"
}

Tested using v1.0 and beta for OneDrive for Business.

Sign up to request clarification or add additional context in comments.

1 Comment

Oh sweet, didn't know you could use PATCH to create a new file/folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.