Overview
This node allows you to perform mutations on documents stored in Sanity.io, a popular headless CMS platform. It supports creating new documents, replacing existing ones, conditionally creating if not present, deleting documents, and patching (partially updating) documents.
Common scenarios include:
- Creating new content entries or assets in Sanity.
- Updating or replacing existing documents with fresh data.
- Deleting obsolete or incorrect documents.
- Applying partial updates to documents without overwriting the entire content.
For example, you might use this node to automate content publishing workflows by programmatically creating or updating blog posts, or to clean up your dataset by deleting outdated records.
Properties
| Name | Meaning |
|---|---|
| Document ID | The ID of the document to operate on. For create operations, if left blank, a random ID will be generated. Required for delete, patch, createOrReplace, and createIfNotExists operations. |
| Document Data | JSON data representing the document content or patch instructions. For "Create" and "Create or Replace", this is the full document JSON. For "Patch", it specifies patch operations. |
| Options | Collection of additional options: - Return Documents: Whether to return the full document(s) in the response (true/false). - API Version: The Sanity API version to use (default: "v2024-06-21"). |
Output
The output contains an array of JSON objects representing the results of the mutation operations performed. Each item corresponds to one input item and includes the mutated document(s) returned from Sanity if the "Return Documents" option is enabled.
If the operation fails for an item and "Continue On Fail" is enabled, the output for that item will contain an error message instead.
No binary data is produced by this node.
Dependencies
- Requires valid Sanity.io credentials including:
- Project ID
- Dataset name
- API token with appropriate permissions to mutate documents
- The node makes HTTP POST requests to the Sanity Mutation API endpoint.
- The API version can be configured via the node's options (default is "v2024-06-21").
Troubleshooting
- Invalid Credentials: If project ID, dataset, or token are missing or invalid, the node will throw an error indicating invalid credentials.
- Missing Document ID: For operations like delete and patch, the Document ID must be provided; otherwise, an error is thrown.
- Invalid JSON in Document Data: If the JSON provided in the Document Data field is malformed, the node throws an error specifying the issue.
- Sanity API Errors: If the Sanity API returns an error (e.g., permission denied, invalid mutation), the node surfaces the detailed API error message.
- Continue On Fail: Enabling this option allows the node to continue processing subsequent items even if some fail, returning error details per failed item.