Graph API: JSON batching to upload item to OneDrive is failing

368 views Asked by At

I am trying to upload a text file to OneDrive using Graph APIs and I also want to update it in the same request using JSON batch.

My JSON request body is below:

{
     "requests":[
      {
           "id":"1",
           "method":"PUT",
           "url":"/drives/b!ddubdQaackeT9nu3x4onivgPxHH2-        
            gpFsk_mo9hryZabqK7w279YSpMqiNodZDaa/items/01BTTSDZ56Y2GOVW772
            5BZO354PWSELRRZ:/abc2.txt:/content",
            "headers":{
                 "Content-Type":"application/octet-stream",
                 "Content-Length":"21"
            },
            "body":{
                "content":"Test content for body"
            }
        },
        {
            "id":"2",
            "method":"PATCH",
            "url":"/drives/b!ddubdQaackeT9nu3x4onivgPxHH2- 
             gpFsk_mo9hryZabqK7w279YSpMqiNodZDaa/items/01BTTSDZ56Y
             2GOVW7725BZO354PWSELRRZ:/abc2.txt",
             "headers":{
                "Content-Type":"application/json; charset=utf-8"
              },
             "body":{
            "fileSystemInfo":{
                "lastModifiedDateTime":"2020-08-09T00:49:37.7758742+03:00"
            }
        },
        "dependsOn":["1"]
        }
   ]
   }

When I send this request from my code, I always get a response "Invalid body for request id: 1. The body must be a valid base64 string or JSON.".

Postman refused to run the above request with the message "Method not allowed".

In the above example, I am uploading and updating text files but my code will have to handle all file types (e.g. images, videos, etc.)

Not sure if I am correctly specifying all the JSON fields. Unfortunately unable to find much info on this. Any help would be appreciated.

0

There are 0 answers