I am in the process of implementing a webhook for Mailgun on my node backend. Having trouble with processing the parameters. The only way I could read the parameters is by parsing the body, in which case the server looks like this:
var server = http.createServer(function (req, res) {
var body = "";
if (req.method == 'POST') {
req.on('data', function (data) {
body += data;
});
req.on('end', function(data) {
body += data;
console.log("response: " + body);
});
}).listen(8080);
The output body is then formatted something like this:
(...)
--5bb8ffb8-e325-492c-b789-3d807dc78e74
Content-Disposition: form-data; name="Message-Id"
<20130503182626.18666.16540@sandbox94d44395c5264485ab775855eb8ff309.mailgun.org>
--5bb8ffb8-e325-492c-b789-3d807dc78e74
Content-Disposition: form-data; name="X-Mailgun-Sid"
WyIwNzI5MCIsICJhbGljZUBleGFtcGxlLmNvbSIsICI2Il0=
--5bb8ffb8-e325-492c-b789-3d807dc78e74
Content-Disposition: form-data; name="attachment-count"
1
Is there any way I could parse the body to get it to a json format? Or if not can I get the parameters in another way? I saw examples for other programming languages, but sadly the information could not be used in my case.