Contentful logo

Contentful Community

Configure Webhook Payload to Include Reference Field Properties

Say I have a Content Type Book with a text field Title and a reference field Author, which in turn has it’s own fields Name (text) and Headshot (media - image).

I want to set up a webhook that fires whenever a Book is created or updated, and I want the payload to include all of the fields, including the nested reference Author fields.

When using the Content Delivery API, I know that I can specify an include property to specify how many nested levels of reference fields I want returned, like so:

await client.getEntries({
  content_type: 'book',
  include: 2
});

I’m wondering if it’s possible to specify something similar in the webhook payload configuration object in order to have the payload itself contain nested reference field properties, rather than just it’s sys fields.

If this is not possible, then how should I approach requesting the nested field properties? If I do a new request with the reference’s ID, is it guaranteed to exist or will I have to wait the 5 minutes it takes for the CDN changes to propagate?

Thanks in advance!

The transformation of the webhook only has access to the proprties if the entity, but not to linked entities.

You could invoke a cloud function with the webhook and have that fetch the CDA. Propagation of changes to the CDN should be fast unless you are throttled because of programmatic writes to the API.

To be save, the cloud function could have a simple polling mechanism comparing the version received in the webhook and the version seen on the CDN.