Overview
The Sanity block connects your workflows to a Sanity dataset. Use it to create new documents, update existing ones, or publish drafts with content generated from your workflow. You’ll find the Sanity block in the Apps section of the block palette.Configuration
Sanity connection
Select the Sanity connection to use. Each connection points to one project and dataset. To add a new connection:- Click the connection dropdown.
- Select Add new connection.
- Enter your project ID, dataset, and API token.
- Name your connection for easy identification.
Selecting a different connection clears the document type, selected document, and field mappings.
Action
Choose the operation to perform.Document type
Enter the document type to work with, for examplepost. Use the exact _type from your Sanity Studio schema. Slate suggests types it finds in your dataset as you type.
Create document
Document ID
Give the new document a stable ID. Slate uses the ID to avoid duplicate documents if the block runs again.- Use letters, numbers, underscores, dashes, or dots, up to 128 characters.
- Leave Document ID empty only if you map a non-empty field named
slug. Slate then builds the ID from the document type and slug, for examplepost.my-first-post.
Update document
Exact document and revision
Select the document to update. The list shows up to 100 of the most recently updated documents of the selected type, each labeled Draft or Published. Slate pins the document’s current revision when you select it. If the document changes after that, including from an earlier run of this block with different values, the update fails. Select the document again to pin its latest revision. Only the fields you map are changed. With Save as draft on, Slate writes your changes to the document’s draft and creates the draft if it doesn’t exist.Publish draft
Exact draft and revision
Select the draft to publish. Only drafts appear in this list. If the type has no drafts, the block shows “No draft documents are available for this type.” Like updates, publishing uses the pinned revision. If the draft changes after you select it, the block fails. Select the draft again to pin its latest revision.Field mappings
Map your workflow data to document fields. You need at least one mapping. Slate infers field hints from recent documents of the selected type. Click a suggested field name to add it, or click Field to add a row and type the field name. Confirm fields that don’t appear in the hints in Sanity Studio. Each row has a field name, a type, and a value. Field names must match your schema and can’t start with an underscore. The value can be static text or a placeholder from a previous step. The type sets how Slate formats the value:
For
portableText, choose the source format: auto, markdown, html, or plainText. Portable Text conversion doesn’t support images, tables, figures, video, or inline CSS. Map those to separate schema fields.
Example mapping:
Save as draft
Toggle whether Create document and Update document write a draft or the live document.- On (default): Content is saved as a draft for review in Sanity Studio.
- Off: Content is written to the live document immediately. Use this only when the workflow is allowed to write live content.
Output
The Sanity block returns the created, updated, or published document.{{step_n.output.documentId}}.
Error Handling
Define what happens if the block fails. Options:- Terminate workflow: Stop the workflow as soon as the block fails.
- Continue execution: Ignore the failure and move on to the next step.
- Retry: Run the block again until it succeeds, up to the Number of retries you choose (1–5). If every retry fails, the workflow stops at this block.
Best Practices
- Keep Save as draft on while you test the workflow.
- Map a
slugfield or set a Document ID so repeat runs don’t create duplicates. - Check field names and types against your Sanity Studio schema.
What’s Next
- Read the Sanity integration guide to manage connections
- Learn about the Loop Block to process multiple items
- See Liquid Templating for data transformation
- Explore the LLM Block to generate content for Sanity
- Check the Human Review Block for approval workflows