Overview
By default every webhook call:- uses the
POSTHTTP method - has the
Content-Typeheader set toapplication/vnd.contentful.management.v1+json - does not have the
Content-Lengthheader set - sends a predefined body depending on the triggering event (as described above)
transformation property of a webhook definition allows you to define:
- a custom HTTP method
- a custom
Content-Typeheader - if automatically computed, a
Content-Lengthheader should be included. - a custom webhook call body that may or may not make use of the default webhook body.
NOTE:The
transformation property is an optional object containing the following properties. None of these properties are required.transformation.method can be one of:
POST(default)GETPUTPATCHDELETE
transformation.contentType can be one of:
application/vnd.contentful.management.v1+json(default)application/vnd.contentful.management.v1+json; charset=utf-8application/jsonapplication/json; charset=utf-8application/x-www-form-urlencodedapplication/x-www-form-urlencoded; charset=utf-8
transformation.includeContentLength can be either true or false. If true the Content-Length header will be present with its value set to automatically computed byte length of the request body.
transformation.body can be any arbitrary JSON data structure. It will be used as the webhook call body.
It’s possible to use values from the original webhook payload in the transformed body. This can be achieved by JSON pointers in the body JSON. Depending on the referenced data either whole values or strings are resolved.
URL transformation
Webhook URLs can contain JSON pointers that are resolved to values from the original payload. The value resolution always follows the string template resolution logic. For example, a webhook defined as follows will result in a call tohttps://my-webhook-endpoint.com/my-entry-1 for an entity with ID my-entry-1.
Header transformation
Custom header values can contain JSON pointers as described below. This is achieved by JSON pointers that are resolved using the string template resolution logic. The following header definitionResolution strategies
Resolving a whole value
- In your data structure, introduce a string value that starts with
{and ends with}in a place you want to resolve the original value - In between curly braces put an absolute JSON pointer to the property you want to resolve; the original webhook body is stored in the
payloadtop-level namespace - The string value containing a pointer will be replaced with the resolved value
Using string templates
- In your data structure, introduce a string value that contains an absolute JSON pointer to the property you want to resolve, wrapped with
{and} - The original webhook body is stored in the
payloadtop-level namespace - JSON pointers will be replaced with resolved values
- All values, including complex ones, will be stringified
Helpers
In some cases, there can be a need for trimming or slightly modifying certain fields before delivering them to the webhook target. Contentful provides numerous helpers that can be used at the transformation level. For example:content field with first two paragraphs. If the content field has more than two paragraphs, the rest of the text gets trimmed. In addition to
trimming content, helpers are useful in modifying or refining content. Following is another transformation, using the strip-stop-words helper:
content field. For example:
| Helper name | Parameter | Description |
|---|---|---|
| first-chars | Number | Selects first n characters of the field.Example: { first-chars 6 /payload/fields/content/en-US } |
| first-words | Number | Selects first n words of the field.Example: { first-words 12 /payload/fields/content/en-US } |
| first-paragraphs | Number | Selects first n paragraphs of the field.Example: { first-paragraphs 3 /payload/fields/content/en-US } |
| strip-stop-words | - | Strip out stop words (only English is supported). Example: { strip-stop-words /payload/fields/content/en-US } |
| strip-markdown | - | Strip out Markdown markup. Example: { strip-markdown /payload/fields/content/en-US } |
| stringify | - | Stringify the value pointed to. Example: { stringify /payload/fields } |
Transformation context
When transforming request body, URL, and headers, JSON pointers are used to resolve values. Values are resolved from a context object. Currently the context object has the following properties:payloadcontains the original webhook payloadtopicis a string containing the webhook topicuseris a stripped-down version of aUserentity for the user who executed action triggering the webhook call; the only available pointer is{ /user/sys/id }