SOLVED

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

Brass Contributor

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?

 

MultiPart response.pngMultiPart body.png

 

 

 

2 Replies
best response confirmed by Dawid van Heerden (Brass Contributor)
Solution

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'))

 

DawidvanHeerden_0-1679965407478.png

 

 

 

DawidvanHeerden_1-1679965407487.png

 

 

 

DawidvanHeerden_2-1679965407490.png

 

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

1 best response

Accepted Solutions
best response confirmed by Dawid van Heerden (Brass Contributor)
Solution

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'))

 

DawidvanHeerden_0-1679965407478.png

 

 

 

DawidvanHeerden_1-1679965407487.png

 

 

 

DawidvanHeerden_2-1679965407490.png

 

View solution in original post