NOTE: This feature is only available for customers on our Premium pricing plan.
NOTE:
For information on using webhooks with the Content Management API, see the webhook CMA documentation.
Webhook payloads
You can view a webhook payload in an entity JSON object. To view an entity JSON object for:- Content type - Open the JSON Preview in the content type editor.
- Entry - An entry JSON can be previewed with the JSON Viewer app.
Environment aliases and webhooks
Webhooks can be triggered for an environment alias using thefilters property of a
webhook just like environments. Webhooks only trigger for a given environment alias if it is used via that alias. Example: for a webhook set to trigger on the master environment alias only
-
Sending a
PUT spaces/<space-id>/entries/my-blog-postwould trigger the webhook -
Sending a
PUT spaces/<space-id>/environments/master/entries/my-blog-postwould trigger the webhook -
Sending a
PUT spaces/<space-id>/environments/environment-to-serve/entries/my-blog-postwould not trigger the webhook
Filtering
Sometimes it is necessary to filter webhooks based on the properties of the entity that triggered the webhook. The most common examples are:- filter webhooks by environment ID (e.g. only trigger the pre-release test suite on a CI service for the environment with ID
staging) - filter webhooks by entity ID (e.g. only trigger for a specific entry, asset or content type ID)
- filter webhooks by content type ID (e.g. only trigger for entries of a specific content type ID)
Note: If a filter is evaluating a property that is not present on the entity, it will evaluate to
false and not trigger the webhook. E.g. a webhook for topics Entry.publish and Asset.publish filters on a specific content type ID. As assets don’t have a content type, all webhooks which are triggered by Asset.publish will be muted by the filter.Retry Policy
Contentful webhooks using a default retry policy will attempt delivery of a webhook and, if it fails with a 429 or 5xx response, re-attempt delivery up to 2 additional times with approximately a 30 second delay between each attempt. This results in a total of 3 attempts over a 1 minute window; after which it is considered failed.Idempotency
Although Contentful makes a best effort attempt to ensure that webhooks are only delivered successfully exactly once for a given event, it is possible on rare occasions in the case of server failure that a webhook may be sent more than once for the same event. It is recommended that you configure your webhook consumer to be idempotent, meaning that it will do work exactly once for a given event, even if it receives duplicate webhook requests. To accomplish this, use theX-Contentful-Idempotency-Key header, a unique SHA256 hash of the webhook event, to deduplicate requests sent to your servers.
Timeouts
Webhook requests will timeout if the recipient server does not respond within a maximum of 30 seconds. A webhook request that times out will be considered failed and will not be retried. Because of this, it is recommended that processing of webhooks be done asynchronously.save and auto_save webhooks
The Contentful web application automatically saves changes in all documents you are working on. Contentful considers documents edited in the last 5 seconds as active and uses that information to call the webhook integrations you have configured.
If you edit an entry in the web app for one minute, and you have a webhook configured to be called for auto_save actions, the defined webhook will be sent 12 times (60 seconds divided by 5 seconds).
When you call the sdk.entry.save() method provided by the App SDK an auto_save webhook is sent.
If you update an entry or asset via the Content Management API or an App, the save webhook is sent.
Customizing webhook calls
By default every webhook call:- uses the HTTP
POSTrequest method - has the
Content-Typeheader set toapplication/vnd.contentful.management.v1+json - sends a predefined body depending on the triggering event
Note: Per W3C RFC-9110,
GET and DELETE requests should not have a request body. As such, Contentful webhook calls do not contain a body for these request methods.