Set filepath of created folder/file in OneDrive

%3CLINGO-SUB%20id%3D%22lingo-sub-2268199%22%20slang%3D%22en-US%22%3ESet%20filepath%20of%20created%20folder%2Ffile%20in%20OneDrive%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2268199%22%20slang%3D%22en-US%22%3E%3CDIV%20class%3D%22question-body%20post-body%22%3E%3CP%3EHi%20there%2C%20this%20is%20INCREDIBLY%20basic%20so%20please%20forgive%20my%20ignorance%20but%3A%3C%2FP%3E%3CP%3EHow%20can%20I%20modify%20the%20filepath%20for%20a%20POST%20request%20through%20MS%20Graph%20to%20write%20a%20file%2Ffolder%20to%20OneDrive%3F%3C%2FP%3E%3CP%3EAt%20present%20the%20below%20will%20write%20to%20the%20root%20directory%20of%20OneDrive%3A%3C%2FP%3E%3CP%3E%7B%3CBR%20%2F%3E%22name%22%3A%20%22Foo%22%2C%3CBR%20%2F%3E%22folder%22%3A%20%7B%7D%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3EHowever%2C%20how%20would%20I%20make%20create%20a%20folder%20in%20a%20path%20such%20as%20%22Documents%5CFoo%22%3F%3C%2FP%3E%3CP%3EI've%20just%20been%20playing%20around%20with%20it%20in%20Graph%20Explorer%20but%20can't%20work%20it%20out.%3C%2FP%3E%3CP%3EThanks!%3C%2FP%3E%3CP%3ERich%3C%2FP%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2268199%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAPIs%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EGraph%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOneDrive%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional Visitor

Hi there, this is INCREDIBLY basic so please forgive my ignorance but:

How can I modify the filepath for a POST request through MS Graph to write a file/folder to OneDrive?

At present the below will write to the root directory of OneDrive:

{
"name": "Foo",
"folder": {}
}

However, how would I make create a folder in a path such as "Documents\Foo"?

I've just been playing around with it in Graph Explorer but can't work it out.

Thanks!

Rich

1 Reply
Hi,

I really don't know if this could be the same or maybe I am completely wrong, but some time ago I needed to do the same with the email inbox. I needed to create a subfolder inside the inbox/root folder. After some digging I found out, I needed the fetch the ID of the root folder first before I could create a subfolder

A part of the blog ( I still need to publish :( )

----------------------------------------------------------------------------------------------------
Most of the script was already published on the internet but I needed it to create a subfolder inside the inbox not in the root of the mailbox. So I changed some parts. Let’s break down what I changed:

To create a subfolder inside the Inbox folder, you will need to ID of the inbox folder. Otherwise it does not work.

$Mailboxfolders = Invoke-RestMethod -Uri $Uri -Headers $Header -Method Get -ContentType "application/json"
$mailboxinboxid = $mailboxfolders.id

Now we have the inbox ID we can change the URI were the subfolder need to be created

"https://graph.microsoft.com/v1.0/users/$mailbox/mailFolders/$mailboxinboxid/childfolders