Search code examples
postmanmicrosoft-graph-apionedrive

Uploading a small text file to OneDrive API / MS Graph


What's the right content schema/format or protocol to use to upload a small text file to OneDrive? I'm authenticating correctly, etc., but the docs don't seem to work...

__

I'm following the documentation, exactly - and for sanity check - using Postman.

Specifically, this example from the docs:

PUT /me/drive/root:/FolderA/FileB.txt:/content
Content-Type: text/plain

The contents of the file goes here.

Error: "Entity only allows writes with a JSON Content-Type header.",

--

So I tried putting the body in a json and changing the content-type to json. I'm actually not sure what the right json schema is...

Error: "Property file in payload has a value that does not match schema."

--

I tried fiddling a bit with PUT /me/drive/root:/FolderA/tester.txt:/content

{ 
  "name": "tester.txt",
  "file":  { } 
}

But got Error: The name in the provided oneDrive.item does not match the name in the URL


Solution

  • It turned out that the : needs to be at the end of the file path...

    Previously, I had tried using /me/drive/root:/FolderA:/FileB.txt:/content instead of /me/drive/root:/FolderA/FileB.txt:/content