capabilities.work

Query Then Patch Document

A 2-step recipe with Sanity. We can help you get access.

Recipe · 2 steps

Query Then Patch Document

with Sanity

Locate a document by a GROQ filter and patch it if it exists.

  1. Run a GROQ query that returns the id of the first document matching the supplied filter expression.
  2. Apply a patch mutation that sets the supplied fields on the matched document id.
What you'll need to have ready
  • projectId: The Sanity project id that scopes the API endpoint.
  • apiToken: Sanity project API token used as a Bearer credential.
  • dataset: Dataset name to query and mutate.
  • filter: A GROQ filter expression selecting the target document (e.g. _type == "post" && slug.current == "hello").
  • set: Map of field name/value pairs to set on the matched document.
For your developer

Arazzo workflow sanity:query-then-patch-document, 2 operations: queryDocumentsPost → mutateDocuments. Specs on APIs.io.