mikeal/request — Issue #91: Body parameters for POST request not being set correctly
Author: KyleAMathews
Created: 2011-10-24 01:28:33+00:00
State: open

I've been trying for awhile to integrate a little node.js app I'm writing with the MailGun API. I'm persistently running into troubles.

The following is my code. Everything seems to be setup correctly but whenever I run it, MailGun returns HTTP 400 and the message that the 'from' parameter is missing.

So apparently nothing from my body object is being sent. What am I missing or doing wrong here? Help is greatly appreciated.

```coffeescript
request = require('request')
querystring = require('querystring')
url = require('url')
mailgun_uri = url.parse('https://api.mailgun.net/v2/kyle.mailgun.org/messages')
mailgun_uri.auth = 'api:key-4efruk6kp1y6nrafq7zhpoipbpmtv476'
body = querystring.stringify(
from: 'bluemoon@nowhere.com'
to: 'mathews.kyle@gmail.com'
subject: 'hello'
text: 'testing request'
'o.testmode': 'true'
)

console.log body

request(
url: mailgun_uri
method: 'POST'
headers:
'content-type': 'x-www-form-urlencoded'
body: body
(error, response, body) ->
console.log response.statusCode
console.log body
)
```