> For the complete documentation index, see [llms.txt](https://docs.whalesync.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.whalesync.com/sync/connectors/sanity.md).

# Sanity

Two-way sync Sanity documents with Airtable, Notion, Google Sheets, and more. Covers Studio schema deployment, API tokens, supported fields, and publishing.

## Sanity Connector Guide

This guide covers how to connect Whalesync to a [Sanity](https://www.sanity.io) project, what you need to do in Sanity first, and which fields sync.

In Whalesync terms, a Sanity **dataset** is the base you pick, each **document type** in your Studio schema is a table, and each **document** is a record.

### Before you connect: deploy your Studio schema

> [!WARNING]
> Whalesync reads your document types and fields from the Studio schema that is **deployed to your dataset**. Sanity's Content Lake has no built-in schema, so until you deploy one Whalesync cannot list any tables. A dataset without a deployed schema shows as **No schema deployed** in the dataset picker.

Deploying takes one command in your Sanity Studio project (Studio 3.88 or newer):

```bash
npx sanity schema deploy
```

Run it as a logged-in Studio developer, or with an Editor-role token in `SANITY_AUTH_TOKEN`. See Sanity's guide: [Schema deployment](https://www.sanity.io/docs/apis-and-sdks/schema-deployment).

Whenever you change your Studio schema, deploy it again and then refresh the schema in Whalesync so the new fields appear.

### Connecting to Sanity

Whalesync connects with a Sanity API token. See [Authorize Sanity](https://docs.whalesync.com/sync/connectors/sanity/authorize-sanity.md) for the steps to create one.

1. In Whalesync, choose Sanity and paste the token.
2. If the token can access more than one project, enter the **Project ID** as well. Robot tokens are usually scoped to one project, so most people can leave it blank.
3. Pick the dataset to sync. Datasets without a deployed schema are listed but cannot be selected until you deploy one.

### Syncing Data

Every document type in the deployed schema is available as a table, including types that have no documents yet. Nested objects (for example an `seo` object with `metaTitle` and `metaDescription`) appear as separate fields named `seo / Meta title`, so each part can be mapped on its own.

## Supported Fields

Whalesync does not support every Sanity field type yet. If you need one that is missing, [reach out and let us know](https://docs.whalesync.com/resources/support.md).

<table><thead><tr><th>Sanity type</th><th>Status</th><th>Notes</th></tr></thead><tbody>
<tr><td>String</td><td>✅ Supported</td><td>A string with an <code>options.list</code> is offered as a select, but Whalesync does not enforce the list.</td></tr>
<tr><td>Text</td><td>✅ Supported</td><td></td></tr>
<tr><td>Number</td><td>✅ Supported</td><td></td></tr>
<tr><td>Boolean</td><td>✅ Supported</td><td></td></tr>
<tr><td>Date</td><td>✅ Supported</td><td>Date only, no time.</td></tr>
<tr><td>Datetime</td><td>✅ Supported</td><td></td></tr>
<tr><td>URL</td><td>✅ Supported</td><td></td></tr>
<tr><td>Email</td><td>✅ Supported</td><td></td></tr>
<tr><td>Slug</td><td>✅ Supported</td><td>Synced as the slug text.</td></tr>
<tr><td>Reference (one target type)</td><td>✅ Supported</td><td>Synced as a link to the target document type. Weak references stay weak.</td></tr>
<tr><td>Array of references</td><td>✅ Supported</td><td>Synced as a multi-link field.</td></tr>
<tr><td>Array of strings</td><td>✅ Supported</td><td></td></tr>
<tr><td>Portable Text (block content)</td><td>✅ Supported</td><td>Synced as HTML, including image and code blocks when your Studio schema allows them.</td></tr>
<tr><td>Image</td><td>✅ Supported</td><td>Synced as the image's CDN URL. Writing a URL uploads the image to Sanity.</td></tr>
<tr><td>File</td><td>✅ Supported</td><td>Synced as the file's CDN URL. Writing a URL uploads the file to Sanity.</td></tr>
<tr><td>Object</td><td>✅ Supported</td><td>Flattened into one field per sub-field, up to three levels deep. Deeper objects are synced as JSON, read only.</td></tr>
<tr><td>Reference (several target types)</td><td>➡️ Supported (1-Way)</td><td>Read only. Whalesync links point at one table, so the target document id is synced as text.</td></tr>
<tr><td>Geopoint</td><td>✅ Supported (as JSON)</td><td>Read only.</td></tr>
<tr><td>Array of objects or images</td><td>✅ Supported (as JSON)</td><td>Read only.</td></tr>
<tr><td>Fields marked <code>readOnly</code> in the Studio</td><td>➡️ Supported (1-Way)</td><td>Read only in Whalesync too.</td></tr>
<tr><td>Cross-dataset and global references</td><td>✅ Supported (as JSON)</td><td>Read only.</td></tr>
</tbody></table>

### Additional Fields

Whalesync adds fields that are not part of your Studio schema.

<table><thead><tr><th>Field</th><th>Explanation</th><th>Writable</th></tr></thead><tbody>
<tr><td>Record ID</td><td>The document's <code>_id</code>. When creating a document from another app, map this field to choose the id; it cannot be changed afterwards.</td><td>Once, on create</td></tr>
<tr><td>Status</td><td><strong>Draft</strong>, <strong>Changed</strong>, or <strong>Published</strong>. Shows which versions of the document exist, and setting it publishes the document, keeps your edits unpublished, or unpublishes it. Must be mapped. See <a href="#status-field">Status field</a>.</td><td>Yes</td></tr>
<tr><td>Created at</td><td>The document's <code>_createdAt</code>.</td><td>No</td></tr>
<tr><td>Updated at</td><td>The document's <code>_updatedAt</code>. When a draft exists, this is the draft's timestamp.</td><td>No</td></tr>
</tbody></table>

## Status field

Sanity stores a document's published version and its draft as two separate documents. So you can sync a whole document type to one table in your other app, Whalesync shows the pair as one record and adds a **Status** field that says which versions exist. When a draft exists, the record shows the draft's values.

Every Sanity table mapping must include Status. Whalesync uses it to tell an edit meant for the live document from one meant for a pending draft, so the field mapping screen shows an error until it's mapped.

| Status | Draft exists? | Published exists? | What it means |
| --- | --- | --- | --- |
| **Draft** | ✅ | ❌ | The document only exists as a draft: it has never been published, or it was unpublished. Your edits go to the draft. To publish it, change Status to **Published**. |
| **Published** | ❌ | ✅ | The document is live and hasn't changed since it was last published. Edits from your other app go live right away. To keep edits unpublished, change Status to **Changed** first. If someone edits the document in the Studio, the Studio creates a draft and Status becomes **Changed**. |
| **Changed** | ✅ | ✅ | The document is live, and it has changed since it was last published. Your edits go to the draft. To publish them, change Status to **Published**. To unpublish the document, change Status to **Draft**. |

### Changing Status

| Change | Result |
| --- | --- |
| Draft → Published | Publishes the document for the first time. |
| Published → Changed | Starts a new version by copying the live document into a draft. Any other edits in the same change go into the draft. Editing in the Studio does this automatically. |
| Changed → Published | Publishes the draft, including any other edits made in the same change, and removes the draft. |
| Published → Draft, or Changed → Draft | Unpublishes the document. It's taken down, and its content, including any pending edits and any other edits in the same change, is kept as a draft. |
| Draft → Changed | Not allowed. Changed means a live document with pending edits, and this one has never been published. |
| Status cleared (empty) | Not allowed. |

Discarding a draft can only be done in the Studio.

When a change isn't allowed, nothing is written to Sanity, and the record shows a sync issue until Status is set to an allowed value. The issue says one of:

* "Status Changed means a published document with unpublished edits, and this document has never been published. Set Status to Draft or Published."
* "A Sanity document's Status can't be empty. Set it to Draft, Changed, or Published."

> [!WARNING]
> Sanity won't unpublish a document while another document, published or draft, has a strong reference to it. The sync issue lists the documents that reference it. Remove those references, or make the reference fields weak in your Studio schema, then retry the sync. To keep the document live instead, set Status back to **Published** or **Changed**. The same rule applies when deleting a record would delete a referenced document.

### New records

* **Status empty or Published:** the document is created and published.
* **Status Draft:** the document is created as a draft.
* **Status Changed:** not allowed, since a new document has no live version.

### Common setups

* **Your other app is the source of truth:** keep Status at **Published**, and every edit goes live.
* **Review before publishing:** create records with Status set to **Draft**. An editor reviews and publishes them in the Studio, or you set Status to **Published**.
* **Prepare the next version of a live page:** set Status to **Changed**, edit the record over as many syncs as you like, then set Status to **Published** to put the edits live.
* **Take a page down:** set Status to **Draft**. The content is kept as a draft, so you can publish it again later.

Deleting a record removes both the published document and its draft.

## Things to Keep in Mind

* **The deployed schema is the schema.** A field you add in Studio code does not exist for Whalesync until you run `npx sanity schema deploy` again and refresh the schema in Whalesync.
* **The token needs the Editor role.** A Viewer token can read your dataset but every create, update, and delete fails with a permissions error.
* **Sanity refuses to delete a referenced document.** If another document holds a strong reference to it, Sanity blocks the delete until the reference is removed or made weak.
* **Content Releases are not synced.** Documents that only exist inside a release are ignored.
* **Studio autosaves as you type,** so a document you are editing in the Studio updates its draft many times. Whalesync syncs the latest state.
