-1

I have copied the (HTML) source code from a received email just to have the template/format of that email, and this is the error message that I am receiveing when running the API:

Internal : Unexpected error Error during Web API HTTP Request
HTTP Status Code: 400
HTTP Response Content: {
  "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": {
      "date": "2020-12-02T17:01:05",
      "request-id": "3ab50fc1-0c13-4536-96db-bf6b9b7a736d",
      "client-request-id": "3ab50fc1-0c13-4536-96db-bf6b9b7a736d"
    }
  }
}

I have tested basic commands using HTML such as making text bold and line breaks which work, but anything more complex and I will receive an error.

Update** Thank you for your response guys, the call that I'm using looks like this:

{
  "message": {
    "subject": "[Subject]",
    "body": {
      "contentType": "HTML",
      "content": "[Email Body Content]"
    },
    "toRecipients": [
      {
        "emailAddress": {
          "address": "[Email Address]"
        }
      }
    ],
    "internetMessageHeaders":[
      {
        "name":"x-custom-header-group-name",
        "value":"Nevada"
      },
      {
        "name":"x-custom-header-group-id",
        "value":"NV001"
      }
    ]
  }
}

**Another update ** Upon changing the content type to text/html is recieved this error:

Internal : Unexpected error Error during Web API HTTP Request
HTTP Status Code: 415
HTTP Response Content: {"error":{"code":"RequestBodyRead","message":"A supported MIME type could not be found that matches the content type of the response. None of the supported type(s) 'Microsoft.OData.ODataMediaType, Microsoft.OData.ODataMediaTyp...' matches the content type 'text/plain; charset=utf-8'."}}

note i also have tried text/plain as the content type.

Thank you

DomF
  • 13
  • 5
  • 1
    (1) Share the API call that you're using (2) Can you repro the issue using POSTMAN/Graph Explorer as well? – Dev Dec 02 '20 at 17:05
  • 1
    Do you have some code you can share that reproduces the error? – DomBurf Dec 02 '20 at 19:57
  • Thank you for your answers, I have edited the post to show the call. I have reproduced in Postman and still the same outcome. I am sure it has to do with the content type but i cannot work it out. Thanks – DomF Dec 04 '20 at 17:05
  • Let me check it out. – Dev Dec 04 '20 at 19:53

1 Answers1

1

Ok, I tried the above payload (just updated the email address) and tested with Microsoft Graph Explorer. It works for me :)

Here's the payload:

{"message":{"subject":"[Subject]","body":{"contentType":"HTML","content":"[Email Body Content]"},"toRecipients":[{"emailAddress":{"address":"test@domain.onmicrosoft.com"}}],"internetMessageHeaders":[{"name":"x-custom-header-group-name","value":"Nevada"},{"name":"x-custom-header-group-id","value":"NV001"}]}}

Here's the snapshot: enter image description here

Dev
  • 2,428
  • 2
  • 14
  • 15
  • Thank you for the response.Does this work if you copy the source code from an email with images and css in its code to the message body? Thanks – DomF Dec 08 '20 at 14:58
  • I havent tested email with images/css in message body, but it should work. If you face any issues, just report back here. If it works, consider upvoting the above answer - so it can be useful to others in the community as well ;) – Dev Dec 08 '20 at 15:34
  • can you please see if it accept inline css – Flame alchemist Jun 09 '22 at 13:51