Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive
Back to changelog

New GROQ-Powered Webhooks

A complete revamp of the webhooks API, which allows for sophisticated webhook configuration using GROQ. Read more in the docs, or read the announcement blog post.

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.

Other improvements


In addition to the filter and projection functionality, we’ve made a bunch of other improvements as well:

  • There’s a new UI for webhooks in the management interface and a full RESTful API
  • Webhooks can now be edited after you have created them
  • You can enable and disable webhooks
  • Webhook entries contain more metadata, including name, description, and more
  • You can add custom headers, and specify its HTTP method
  • There’s a new attempts log that makes troubleshooting and testing easier
  • Webhooks support a secret that will be hashed in the request which you can use to authenticate that the request originates from your project
  • We include idempotency keys in the headers, which you can use when syncing data to verify you haven’t received it before
  • Webhook configurations can be shared via URL
  • Webhooks are now guaranteed to include the content changes that caused them
  • Webhooks will now be retried (and are also rate-limited to 60 per second)
  • We also added a `sanity` namespace to GROQ that can be used in projections

Documentation affected by this release

Published October 06, 2021