Contentful logo

Contentful Community

Webhook - include additional parameters in the request's body

Hey there,

I’m looking to include some additional data in my webhook. I see there’s a key:value entry for additional headers on the request, but I’d like to include additional data in the body of the request (namely, adding a key:value into the -d of the CURL request). Am I missing something obvious here or is this not supported?

Thanks!

If you want to add additional data in the body of the webhook request and the custom headers in the webhook settings isn’t enough, the only other way would be to add fields to be content type for which the webhook is setup.

Can you explain what you mean by this quote below?

Thanks!

Hey Charlie,

Custom headers aren’t included in the POST request’s body, hence them not being enough. I’m not too sure what you mean by “add fields to be content type for which webhook is setup”.

In regards to the CURL request, I apologies for the ambiguity.

Basically, I’m looking for a way to replicate as if I’m making a cURL requests and providing the POST requests’s body (as data, the flag for this command is -d).

The specific use case for this is I’d like to kick off a specific job with my CI, CircleCI: https://circleci.com/docs/2.0/api-job-trigger/

It requires me to pass in a hash with some specific keys and values in the requests body. I don’t see a way to set that up in the current webhook UI.

I understand what you mean now! thanks!

So custom headers don’t work because you need it as part of the POST request body, right?

Right now, the only way to do this is to add the fields you need to the content type for which the webhook is reporting. For example, say you have a blog post content type in Contentful with title, slug, and body fields. Every time an author publishes a new blog post you want CircleCI to rebuild your statically generated website (for example). In addition to the title, slug, and body fields, you would need to add the field which CircleCI requires to the blog post content type. This is definitely not a very good way to do this however.

What I would suggest is to use the custom headers as is in the webhook setup, then set up some middleware (using Lambda, now.sh, webtask, etc.) which receives the webhook from Contentful and takes the headers and puts it into the request body which it then passes it along to CircleCI. This is also not great, but better than what I originally suggested.

Don’t worry though! We have a product update in the pipeline for this exact use case which will allow you to define a webhook transformation which will alter the webhook body to align with what your particular webhook receiver (CircleCI in this case) is expecting. We don’t have a firm date for releasing this update, but it should be in the next few months. Keep watch at https://www.contentful.com/developers/changelog/