Join us live Sept. 27 – How Sanity and Vercel powered Morning Brew's transformation –>

Migrating the legacy webhook behavior to GROQ-powered Webhooks

If you need to recreate the previous webhook behavior – triggering on all changes, and on a dataset level rather than document-level – you can do so by following these steps:

  1. Create a webhook set to trigger on create, update and delete
  2. Leave the Filter field empty
  3. Add the following to the Projection field
// webhook projection
{
  "transactionId": "Not supported",
  "projectId": sanity::projectId(),
  "dataset": sanity::dataset(),
  "ids": {
    "created": [
    	select(before() == null && after() != null => _id)
    ],
    "deleted": [
      select(before() != null && after() == null => _id)
    ],
    "updated": [
      select(before() != null && after() != null => _id)
    ],
    "all": [
      _id
    ]
  }
}

You can also click this link to get a template with the settings described above.

Was this article helpful?