Search code examples
office365microsoft-graph-apionenote-api

Microsoft graph batch calls for OneNote page renames fails with message "Invalid JSON body for request id"


I am doing a graph batch call to rename OneNote page title, I am following these samples provided on the graph website.

Following is the example with a single request for simplicity(typically in my scenario there are more than one requests).

POST https://graph.microsoft.com/v1.0/$batch

{  
   "requests":[  
      {  
         "id":"1",
         "method":"PATCH",
         "url":"https://graph.microsoft.com/v1.0/me/onenote/pages/1-98c2295df76a4067a6036efc6a8f6f74!84-f754d551-02d2-4416-af42-8fcc644f10e6/content",
         "headers":{  
            "Content-Type":"application/json"
         },
         "body":[  
            {  
               "target":"title",
               "action":"replace",
               "content":"2 - Test1"
            }
         ]
      }
   ]
}

I am getting a 400 response for this call with the following message

{
"error": {
    "code": "BadRequest",
    "message": "Invalid JSON body for request id : 1",
    "innerError": {
        "request-id": "2cc6bfcc-6ce5-471c-af37-181ef0dd5a9e",
        "date": "2018-10-22T10:06:54"
    }
  }
}

The same request if I do in a single call without batch it works fine. I have done enough investigation couldn't find any sample where an array is passed in the batch request body. Is it like array content is not supported in the batch request body or OneNote calls are not fully compatible with batching?.

Note: I tried giving the content in the body without array that also fails with the message "Specified method is not supported."


Solution

  • The url must be relative, as shown here

    Try this with your code:

    "url":"/me/onenote/pages/1-98c2295df76a4067a6036efc6a8f6f74!84-f754d551-02d2-4416-af42-8fcc644f10e6/content"