0

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.

mrivanlima
  • 561
  • 4
  • 10
user13260866
  • 131
  • 1
  • 2
  • 9
  • Share the response log (specially the requestid, timestamp) – Dev Dec 04 '20 at 19:25
  • I see that you use dependson, it means that if an individual request fails, any request that depends on that request fails with status code 424 (Failed Dependency) - i think you're facing this. In such situation, i would do this. First make sure both the calls work properly as individual and then try the JSON batching to see if it works. – Dev Dec 04 '20 at 19:27
  • Does it helped? – Dev Dec 07 '20 at 08:18
  • The issue was with the format of the body. I added body in Base 64 encoded format and the things started working fine. – user13260866 Dec 28 '20 at 12:03
  • Wonderful update. Glad that it worked. – Dev Dec 28 '20 at 17:18
  • Move the answer below. So it will be useful to others as well :) – Dev Jan 04 '21 at 11:14

0 Answers0