Unable to read JSON request payload.
I get the error : "{ "error": { "code": "BadRequest", "message": "Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format.", "innerError": { "request-id": "c9608a1e-84c8-4aae-bb2c-09b7dc16ed8c", "date": "2017-02-04T14:37:28" } } }"
Hi @FreedomPaul . Thanks for reporting this issue. When are you getting this error? Can you log in?
Yes,I can log in. when I choose the Send Mail button,I get that error:BadRequest. I try to debug and I see that JSON.
Thanks for the info. I wasn't able to repro the issue, so I'll ask the product team to look at your request in the service logs to see if they can help troubleshoot.
Hi @DianeD . Today I find out the cause of that issue is Content-Length .
I suppose the emailAsPayload.Message.Body.content variable in this sample contains some Chinese characters because of my Office 365 account name when the sample is running.My Office 365 account name using my Chinese name.It causes that error:Unable to read JSON request payload.
I suddenly find a solution from the Internet and then I change some code , as follows:
===================================================
In requestUtil.js file, changing the value of Content-Length:
function postSendMail(accessToken, mailBody, callback) {
var outHeaders = {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + accessToken,
' Content-Length': Buffer.byteLength(mailBody,'utf8')//for utf-8 characters
// 'Content-Length': mailBody.length//by default
};
...
....
}//end
===================================================
And then the sample runs successfully.Now I can send mail contains some Chinese characters!
Thanks for letting us know! I'll make a note of this in the sample.
Comment added. Thanks again @FreedomPaul !
@DianeD So why not just replace the method? I don't think it will cause any unexpected problem.