Really struggling to get this working. I have a webhook definition setup in Contentful. When I publish an entry in Contentful it sends an HTTP POST request to webhooks.example.com.
At that subdomain I have a NodeJS server running to accept the request. I've looked at the Contentful API docs, which say the request body should contain the newly published entry.
I've tried 2 methods of receiving the request, neither of which are giving me anything for the request body. First I tried the contentful-webhook-server NPM module:
var webhooks = require("contentful-webhook-server")({
path: "/",
username: "xxxxxx",
password: "xxxxxx"
});
webhooks.on("ContentManagement.Entry.publish", function(req){
console.log("An entry was published");
console.log(req.body);
});
webhooks.listen(3025, function(){
console.log("Contentful webhook server running on port " + 3025);
});
Here the request comes through and I get the message An entry was published
but the req.body
is undefined. If I do console.log(req)
instead, I can see the full request object, which doesn't include body.
So I then tried running a basic Express server to accept all POST requests:
var express = require("express"),
bodyParser = require("body-parser"),
methodOverride = require("method-override");
var app = express();
app.use(bodyParser.json({limit: "50mb"}));
app.use(bodyParser.urlencoded({extended:true}));
app.use(methodOverride("X-HTTP-Method-Override"));
app.post("/", function(req, res){
console.log("Incoming request");
console.log(req.body);
});
Again with this, I get the Incoming request
message but req.body
is empty. I know this method is wrong because I haven't used my webhook username/password.
How do I correctly receive incoming webhook requests and get the body content?