Issue with webhook triggering on document creation in Sanity.io

4 replies
Last updated: Jul 6, 2023
Webhooks and delta-functions
I'm trying to write a webhook that fires whenever a field in a document gets new information. In my mind, that should happen when a document is created, the field in question is updated, and when the document is deleted.

However, when I set the "filter" field of my webhook to look like this:


_type == "someType" && delta::changedAny(someField)
(and mark my webhook to run on both creation, updating and deleting)

The webhook doesn't trigger on creation. I think it should. Am I doing something wrong, or is this the intended behavior?
Jul 5, 2023, 6:59 PM
I’ll ask the Content Lake team if that’s the expected behaviour. It may end up that you need to use the following, but I’ll confirm:

_type == "someType" && delta::changedAny(someField) || before().someField == null)
Jul 5, 2023, 7:30 PM
That would work for the creation use case, but not for the deletion usecase.
Jul 6, 2023, 6:42 AM
Hi
user U
. The team got back to me that the
delta::changed*
functions weren’t intended for create/delete cases, and therefore behaviour is not guaranteed. They’ve suggested going with this approach:

_type == "someType" && delta::changedAny(someField) || delta::operation() == "create" || delta::operation() == "delete"
Jul 6, 2023, 3:00 PM
Alright I’ll see if that works in my usecase
Jul 6, 2023, 3:25 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?