Fixed. "Messages key wrapping the payload caused the error"
Can not create message through Graph Api "UnableToDeserializePostBody"
Just trying to store a message in /messages, so I can add attachemts later. Using Laravel and microsoft graph vendor for the task.
This is the code in question:
$graph = new Graph();
$graph->setAccessToken($this->getAccessToken());
$graphMessage = $graph->createRequest("POST", "/users/" . $email->getFrom()[0]->getAddress() . "/messages")
->attachBody($this->getBody($email))
->addHeaders(['Content-Type' => 'application/json'])
->execute();
The output of this code is next
url : POST https://graph.microsoft.com/v1.0/users/XXXXXX/messages
payload:
{
"message": {
"from": {
"emailAddress": {}
},
"toRecipients": [{
"emailAddress": {
"address": "******@gmail.com"
}
}],
"ccRecipients": [],
"bccRecipients": [],
"replyTo": [],
"subject": "Reporte General de bienes",
"body": {
"contentType": "text",
"content": "Reporte general de bienes a fecha 2023-03-11 00:00:00"
}
}
}
yet I keep receiving next error
Client error: `POST https://graph.microsoft.com/v1.0/users/xxxxx/messages` resulted in a `400 Bad Request` res
ponse:{"error":{"code":"UnableToDeserializePostBody","message":"were unable to deserialize "}}
Any idea?
Microsoft Security Microsoft Graph
2 answers
Sort by: Most helpful
-
-
Zehui Yao_MSFT 5,876 Reputation points
2023-04-10T06:45:19.45+00:00 Hi Carlos Gonzalez Great to know that it works now and thanks for sharing the update here. By the way, since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others.". and according to the scenario introduced here: Answering your own questions on Microsoft Q&A, I would make a brief summary of this thread: [Can not create message through Graph Api "UnableToDeserializePostBody"] Issue Symptom:
/users/xxxxx/messages
resulted in a 400 Bad Request response:{"error":{"code":"UnableToDeserializePostBody","message":"were unable to deserialize "}}
Current status:
Now the issue is fixed. Messages key wrapping the payload caused the error. You could click the "Accept Answer" button for this summary to close this thread, and this can make it easier for other community member's to see the useful information when reading this thread. Thanks for your understanding!