.png)
Sanity Integration Guide
Integrate Sanity content with enterprise applications through HTTP APIs, GROQ queries, mutations, assets, webhooks, and selected GraphQL APIs.
Sanity integration options at a glance
Sanity provides HTTP APIs for GROQ queries, document mutations, transactions, and project or dataset operations. Its asset APIs support image and file upload and retrieval, while webhooks provide selected document-change notifications with filters and projections. Sanity also offers a schema-generated GraphQL API whose availability depends on the project schema and API version. Martini can consume these endpoints, receive Sanity webhook requests through an exposed API, map JSON documents, orchestrate downstream workflows, and securely manage project-specific tokens. For larger synchronizations, Martini can combine paginated queries, checkpoint-based scheduling, deterministic mutations, and reconciliation workflows.
Common Sanity integration patterns
Common Sanity data objects used in integrations
Authentication and security considerations
Token and project security
Sanity normally uses project- and dataset-scoped API tokens for server-to-server queries and mutations. Martini should store tokens, project identifiers, datasets, API versions, and any webhook verification configuration in protected secrets or environment-specific configuration.
Least privilege and request validation
- Grant only the permissions required by each workflow.
- Restrict datasets and document operations by integration purpose.
- Validate webhook methods, payload structure, dataset, and document state before processing.
- Do not assume OAuth is the normal authentication method for Sanity content APIs.
Browser and delivery considerations
Public-read datasets and CORS settings may be appropriate for selected delivery scenarios, but server-side Martini workflows should use authenticated access where content is private or mutations are required.
Operational considerations for Sanity integrations
Pagination and checkpoints
Paginate or partition large GROQ result sets with stable ordering. Store a checkpoint based on document IDs, update metadata, revisions, or another source marker, and run scheduled reconciliation to recover missed webhook deliveries.
Idempotency and retries
Use dataset, document ID, document state, and revision or update markers to construct idempotency keys. Apply controlled backoff for transient HTTP failures and avoid retrying non-idempotent mutations without deterministic IDs or conditional logic.
Schema and state changes
Sanity schemas can evolve from scalar values to references, arrays, or optional fields. Validate required values and define handling for drafts, publication, unpublishing, deletes, and archived content. Pin the API version and test changes before deployment.
Assets and monitoring
Decide whether downstream systems retain Sanity asset URLs or require copied files. Log the project, dataset, document ID, operation, revision, asset, and destination identifier so failed records can be replayed without duplicating successful updates.
Why use Martini instead of scripts or point-to-point integrations?
Centralized orchestration
Martini coordinates Sanity queries, webhooks, mutations, asset operations, and downstream APIs in an explicit workflow rather than scattering logic across scripts or point-to-point calls.
Reusable transformation and rules
Mappings, validation, document-state rules, enrichment, routing, and idempotency behavior can be reused across publishing, commerce, search, and business-system integrations.
Operational control
- Use protected environment configuration for project, dataset, API version, and tokens.
- Support event-driven processing together with scheduled reconciliation.
- Apply controlled retries and error handling around API and mutation operations.
- Expose governed APIs when consumers should not access Sanity directly.
Maintainable integration assets
Martini provides a developer-oriented low-code environment for mapping, workflow orchestration, API consumption, API exposure, monitoring, and custom logic when a Sanity integration requires behavior beyond standard HTTP requests.