Forum Discussion

Dawid van Heerden's avatar
Dawid van Heerden
Brass Contributor
Mar 21, 2023

OneNote create page with multipart/form-data - The multi-part payload was malformed.

Good day,

 

I am trying to create a OneNote page using the Graph OneNote endpoint below, but can't seem to get the multipart right and keep on getting an error that "The multi-part payload was malformed."

https://graph.microsoft.com/v1.0/groups/{id}/onenote/sections

 

Any ideas what could be wrong with the below?

 

 

 

 

  • After working with Microsoft to resolve, it turns out that the Power Automate UI has a tendency to strip out \r aka CR (Carriage Return) aka %0D characters whereas the OneNote API is very picky and requires CRLF end of line characters, so we need to sub LF back in. And the replacement should be in the HTTP action body or there is a good chance they get striped out again and it fails.

     

    If variables(strBody) is your payload;

     

    Content-Length == length(replace(variables('strBody'),uriComponentToString('%A'),uriComponentToString('%0D%A')))

     

    Body == replace(variables('strBody'),uriComponentToString('%0A'),uriComponentToString('%0D%0A'))

     

     

     

     

     

     

     

     

  • After working with Microsoft to resolve, it turns out that the Power Automate UI has a tendency to strip out \r aka CR (Carriage Return) aka %0D characters whereas the OneNote API is very picky and requires CRLF end of line characters, so we need to sub LF back in. And the replacement should be in the HTTP action body or there is a good chance they get striped out again and it fails.

     

    If variables(strBody) is your payload;

     

    Content-Length == length(replace(variables('strBody'),uriComponentToString('%A'),uriComponentToString('%0D%A')))

     

    Body == replace(variables('strBody'),uriComponentToString('%0A'),uriComponentToString('%0D%0A'))

     

     

     

     

     

     

     

     

    • willthmas140's avatar
      willthmas140
      Copper Contributor

      Thanks so much for sharing your findings. This would have taken me forever to figure out.

Resources