user3006609 user3006609 - 2 years ago 140
JSON Question

Parsing Contentful Webhooks (Custom JSON types)

I'm currently using this Contentful-webhook-server to listen for webhooks when content is unpublished.

server.listen(30000, function(){
console.log('Contentful webhook server running on port ' + 30000)

server.on('ContentManagement.Entry.publish', function(req){
console.log('An entry was published!', req);

server.on('ContentManagement.Entry.unpublish', function(req){
console.log('An entry was unpublished!');
console.log('Deleted SOLR ID: ', req);

I'm trying to parse the response I've got but I can't seem to find a way to parse the custom JSON they use in their response. Should I be creating my own server with express or am I missing a way to get the response body in this example code.

Answer Source

The contentful-webhook-server library uses the plain node http module for the server. Thus, the req object is a readable stream that you need to buffer and parse to get the body.

Take a look at for an example.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download