> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hightouch.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Sanity

> Empower your content management through Sanity - a customizable all-code backend for content-driven websites and apps.

## Supported syncing

| Type | Description | Supported Sync Modes | API Reference |
| - | - | - | - |
| **Documents** | Sync data from any source to Sanity | Upsert, Update, Insert | [Documents docs](https://www.sanity.io/docs/http-mutations) |

For more information about sync modes, refer to the [sync modes](https://docs.hightouch.com/syncs/types-and-modes.md#sync-modes) docs.

## Connect to Sanity

Go to the [**Destinations** overview page](https://app.hightouch.com/destinations?from=docs) and click the **Add destination** button. Select **Sanity** and click **Continue**. You can then authenticate Hightouch to **Sanity**.

Enter the following fields into Hightouch:

* **Project ID**: Find your Project ID on the project's main dashboard.
* **API token**: Generate or find your API token for your project under the API tab.

## Sync configuration

Once you've set up your Sanity destination and have a [model](https://docs.hightouch.com/getting-started/concepts.md#models) to pull data from, you can set up your sync configuration to begin syncing data. Go to the [**Syncs** overview page](https://app.hightouch.com/syncs?from=docs) and click the **Add sync** button to begin. Then, select the relevant model and the Sanity destination you want to sync to.

### Syncing documents

Sync data from any source to Sanity documents. Define document schemas and `types` in your Sanity project, and sync document properties and fields to Sanity using Hightouch.

#### Record matching

To match rows from your model to documents in Sanity, you need to select the model column that contains values that match the **ID** field. You can match on any of the following Sanity fields:

* ID
* *custom matching field (recommended unique)*

Refer to the [record matching docs](https://docs.hightouch.com/syncs/record-matching.md) for more information.

> [!NOTE]
>
> In **Insert** mode, Sanity automatically generates an identifier for every new record synced.

#### Field mapping

Hightouch lets you sync document fields via [field mapping](https://docs.hightouch.com/syncs/mapping-data.md).
You can map data from any of your model columns to default and custom document schema fields.
Ensure your model's columns have the same data types as the fields you want to sync to.

Prior to syncing, define your document type's schema in your Sanity project. To write to Sanity documents, map your source fields
to your defined custom document schema fields.

#### Update mode and Upsert mode

Hightouch leverages Sanity's [patch mutation API ](https://www.sanity.io/docs/content-lake/http-patches) to support both Update and Upsert modes. The integration currently uses the `set`
operation, which replaces the values of the fields mapped in your configuration.

> [!WARNING]
>
> We recommend maintaining a clear separation between fields managed by Hightouch and those edited manually in Sanity. Any field mapped to
> Hightouch will be overwritten during updates and upserts. To preserve human-managed content, exclude those fields from your Hightouch mappings.

## Tips and troubleshooting

To see the exact API requests and responses from each sync run, use the [live debugger](https://docs.hightouch.com/syncs/debugger.md). To get notified by Slack, PagerDuty, SMS, or email when a sync fails, set up [sync alerts](https://docs.hightouch.com/syncs/alerting.md). If you run into an issue this page doesn't cover, [contact support](#pylon-chat).
