Hey @jude,
This is an interesting question! I think you can do this if you can modify the endpoint and add some conditional logic there, and have it do some basic diffing on the keywords field. For example, first you’d start by modifying the webhook and adding the create
and update
events (because this will let you better capture changes between versions):
Then, in the webhook body, do a custom payload similar to this:
{
"message": "{{event_type}} event triggered on {{entity_type}}!",
"entity_id": "{{#entity}}{{id}}{{/entity}}",
"event": "{{event_type}}",
"status": "{{entity.meta.status}}",
"current_keywords": "{{entity.attributes.keywords}}",
"previous_keywords": "{{previous_entity.attributes.keywords}}",
"entity": "{{entity}}",
"previous_entity": "{{previous_entity}}"
}
(Those are “Mustache” variables that you can learn about in our docs: https://www.datocms.com/docs/general-concepts/webhooks#customize-the-url-or-http-payload)
Those variables get expanded by us, and your actual webhook payload would look like this:
{
"message": "update event triggered on item!",
"entity_id": "KOS3cnXEQ6KK46jMag04Mg",
"event": "update",
"status": "updated",
"current_keywords": "new keywords",
"previous_keywords": "alpha, beta, charlie, delta",
"entity": "{"id":"KOS3cnXEQ6KK46jMag04Mg","type":"item","attributes":{"title":"This is a test post 7 - keywords changed","keywords":"new keywords"},"relationships":{"item_type":{"data":{"id":"fLNw2cmTTLOqE9lbInQPnA","type":"item_type"}},"creator":{"data":{"id":"627975","type":"organization"}}},"meta":{"created_at":"2024-01-02T20:30:51.280+00:00","updated_at":"2024-01-02T20:38:51.683+00:00","published_at":"2024-01-02T20:38:51.709+00:00","publication_scheduled_at":null,"unpublishing_scheduled_at":null,"first_published_at":"2024-01-02T20:30:51.306+00:00","is_valid":true,"is_current_version_valid":true,"is_published_version_valid":true,"status":"published","current_version":"IoHkZjh0S4-QKKnFGqJDHA","stage":null}}",
"previous_entity": "{"id":"KOS3cnXEQ6KK46jMag04Mg","type":"item","attributes":{"title":"This is a test post 6 - keywords added","keywords":"alpha, beta, charlie, delta"},"relationships":{"item_type":{"data":{"id":"fLNw2cmTTLOqE9lbInQPnA","type":"item_type"}},"creator":{"data":{"id":"627975","type":"organization"}}},"meta":{"created_at":"2024-01-02T20:30:51.280+00:00","updated_at":"2024-01-02T20:37:27.841+00:00","published_at":"2024-01-02T20:37:27.869+00:00","publication_scheduled_at":null,"unpublishing_scheduled_at":null,"first_published_at":"2024-01-02T20:30:51.306+00:00","is_valid":true,"is_current_version_valid":true,"is_published_version_valid":true,"status":"published","current_version":"AFzmw21IQ7CmoBaEUrKxDQ","stage":null}}"
}
In this example, in your webhook handler you could then do some conditional checks:
You can modify the logic as needed, but basically, the webhook payload lets you do these conditionals in your handler as you see fit.
Does that help?