UnableToDeserializePostBody error when testing with the exact example from documentation

Pascal Craponne 1 Reputation point
2021-09-08T11:22:52.153+00:00

Hi,

I want to create a message using MIME format, using the example from page https://learn.microsoft.com/en-us/graph/outlook-send-mime-message#specify-request-header-and-mime-message-body, I get a 400 result with error
{"error":{"code":"UnableToDeserializePostBody","message":"were unable to deserialize "}}
What I know so far is that the message is correctly base 64 formatted (I use the base 64 string from the example), content-type is set to text/plain.
Is there any way to have more details about the failure?
Did anyone have a similar issue?
I’m out of ideas .'(

Thanks.

Microsoft Security Microsoft Graph
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. he-dev 6 Reputation points
    2021-10-02T12:28:55.827+00:00

    I was getting the same error with /me/messages. This is how my request looked like with python:

       body = {  
           "message": {  
               "subject": "test subject",  
               "body": {  
                   "contentType": "HTML",  
                   "content": "test content"  
               },  
               "toRecipients": [{  
                   "emailAddress": {  
                       "address": "******@somewhere.com"  
                   }}]  
           }  
       }  
         
       response = requests.post(create_mail_url, data=json.dumps(body), headers=headers)  
    

    Strangly this works fine with /me/sendMail but when calling /me/messages it was necessary to remove the outer object with body["message"]. This mans that in case of a json message the body is different. Your link points to send-message, I think you should take a look at this page https://learn.microsoft.com/en-us/graph/api/user-post-messages?view=graph-rest-1.0&tabs=http that discribes the format for create-message. There might be similar differences for mime.

    1 person found this answer helpful.

  2. Pascal Craponne 1 Reputation point
    2021-09-08T15:15:43.263+00:00

    Note that this fails when specifying a mailFolder only:

    • A request such as POST /users/{id|userPrincipalName}/messages works
    • But POST /users/{id|userPrincipalName}/mailFolders/{id}/messages fails

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.