Search code examples
jsonmailgunfreshdesk

Posting raw json to mailgun in preparation for using with a Freshdesk webhook


I'm trying to post the following raw data to mailgun using postman, My eventual intended use is to build the request into a freshdesk webhook which will POST raw JSON to a callback URL.

I've set postman to POST the following raw JSON

{
  "from":"[email protected]"
  "to":"[email protected]"
  "subject":"test"
  "text":"working?"
}

Im receiving the response:

{
  "message": "'from' parameter is missing"
}

I'd love to know how I'm formatting the code incorrectly? Thanks


Solution

  • Looking at the following cURL example, you need to POST the data as x-www-form-urlencoded or multipart/form-data.
    https://documentation.mailgun.com/user_manual.html#sending-via-api

    So to make this work in Postman, ensure the following:

    Authorization:
    Type = Basic Auth
    Username = api
    Password = [your API key]

    Headers:
    Accept = text/json

    Body/x-www-form-urlencoded:
    from = [email protected]
    to = [email protected]
    subject = test
    text = working?

    Update...

    To get this to work in Freshdesk you can kludge this a little in the webhook by setting a custom header to indicate x-www-form-urlencoded, then choosing the JSON encoding (so that you can write an "advanced" content string), and then writing your body content as a url-encoded query string.

    This should work as long as you're not using any dynamic placeholder value that has characters needing to be escaped.

    Here's a test I created that worked for me. It's hacky, but it might be enough for your purposes:

    enter image description here