Sanity.io Integration
iContentForge seamlessly integrates with Sanity.io, allowing you to automatically publish AI-generated articles directly to your Sanity dataset. This guide walks you through the connection setup and field mapping process.
Prerequisites
Before you begin, ensure you have:
- An active iContentForge project with generated articles.
- A Sanity.io project with a dataset (typically
production). - Admin or Editor permissions in your Sanity project to generate API tokens.
Generating Sanity API Credentials
iContentForge requires a Write Token to publish content to your Sanity dataset. Follow these steps to generate one:
- Log in to your Sanity.io Manage dashboard.
- Select your project from the list.
- Navigate to Settings > API.
- In the "Tokens" section, click Add API token.
- Configure the new token:
- Name: e.g.,
iContentForge Publish Token - Role: Select Editor (requires write permissions).
- Permissions: Ensure
create,update, andpublishare enabled.
- Name: e.g.,
- Click Generate. Copy the token immediately, as it will not be shown again.
Keep your token secure. Treat the Sanity Write Token like a password. If compromised, regenerate it immediately in your Sanity dashboard and update the connection in iContentForge.
Recommended: The Official Zero-Config Template
If your Sanity schema is highly customized or you are experiencing mapping errors, we strongly recommend using our standard schema. This bypasses all manual field mapping and guarantees 100% compatibility with iContentForge's automated publishing.
- Download
sanity-icontentforge-schema.ts - Place this file inside your Sanity project's
schemas/folder. - Add
icf_postto your document types list inschemas/index.ts(orschema.ts). - Run
sanity deploy. - In iContentForge, just set Document Type to
icf_postand all fields will automatically map!
Connecting iContentForge to Sanity
With your credentials ready, establish the connection:
- In your iContentForge dashboard, go to your Project and open the CMS Integrations tab.
- Click Add New Integration and select Sanity.io from the list.
- Fill in the connection details:
- Project ID: Found in your Sanity project's
sanity.jsonfile or on the API settings page (e.g.,abc123def). - Dataset: The name of the dataset to publish to (e.g.,
production). - Write Token: The API token you generated in the previous step.
- Document Type (Schema): The
_typename of your Sanity document schema for articles (e.g.,post,article,blogPost). Check your Sanity Studio schema files if unsure. - Author Name (Optional): A display name for the author field in published documents.
- Field Type Overrides (Optional JSON): A schema hint object such as
{"body":"portable_text","slug":"slug","tags":"array<string>"}. This enables pre-publish validation so iContentForge can catch type mismatches before the mutation reaches Sanity.
- Project ID: Found in your Sanity project's
How we target only your blogs (Schema Isolation):
Sanity stores all pages (home pages, products, articles) in the same dataset. We prevent your other pages from being affected by strictly routing content based on the Document Type (_type). When you specify post (or your specific blog schema name) in the settings above, every article published by iContentForge is explicitly tagged with _type: "post". Sanity's internal database automatically isolates these submissions and routes them exclusively into your blog list, completely ignoring and protecting your other website pages.
- Click Test Connection. A success message confirms your credentials are valid.
- Click Save & Configure to proceed to field mapping.
Schema-Aware Validation
Sanity is a schema-driven CMS, which means two websites can both use a field named body while expecting completely different value shapes. One site may want Portable Text, another may store plain strings, and another may rely on custom objects.
To reduce failed publishes and broken front-end rendering, iContentForge supports Field Type Overrides in the connector settings. This lets you tell the publisher what your Sanity schema expects for the fields you mapped.
Why this matters
Without schema-aware validation:
- A publish can fail at mutation time because the value shape is wrong.
- A publish can succeed, but render incorrectly in your front-end because the stored value type does not match what your components expect.
- Debugging gets slower because the error only appears after content has already been pushed to Sanity.
With schema-aware validation:
slugfields are validated and wrapped as{ _type: "slug", current: "..." }portable_textfields are checked before publishdatetimefields are normalized as ISO timestampsarray<string>fields are validated before mutation- Invalid combinations are rejected early with a descriptive error
Supported Sanity type hints
Use the optional JSON field in the connector UI to override types for mapped fields:
{
"title": "string",
"slug": "slug",
"body": "portable_text",
"excerpt": "text",
"metaTitle": "string",
"metaDescription": "text",
"categories": "array<string>",
"tags": "array<string>",
"publishedAt": "datetime"
}
This is especially useful when your schema differs from the default assumptions used by iContentForge.
GROQ Schema Field Mapping
After connecting, you must map iContentForge's article data to the fields in your Sanity document schema. This tells iContentForge where to place the title, body, slug, etc.
- In the configuration panel, you will see a list of iContentForge Fields (Source) and empty dropdowns for Sanity Fields (Target).
- For each source field, select the corresponding target field from your Sanity schema.
- The dropdown is populated by fetching your Sanity schema's document type(s).
Default Field Mapping
Here is the standard mapping for a typical blog post schema (post or article):
| iContentForge Field | Recommended Sanity Field Type | Purpose |
|---|---|---|
title | string | The article's main headline (H1). |
slug | slug | The URL-friendly identifier for the post. Stored as { _type: "slug", current: "..." }. |
content | array of block types (Portable Text) | The full content of the article, automatically converted from Markdown. |
excerpt | text or string | A short summary of the article. |
featuredImage | image | The main image for the article. |
seoTitle | string | Custom title for SEO/meta tags. |
seoDescription | text | Custom meta description. |
author | string or reference | Author name or reference to an author document. |
publishDate | datetime | The scheduled publication date & time. |
tags | array of strings | Keywords or categories for the post. |
Portable Text Conversion: iContentForge converts your Markdown content into Sanity's Portable Text format (an array of block objects) automatically. The converter supports:
- Headings:
#,##,###,####h1,h2,h3,h4block styles - Paragraphs: Regular text
normalblock style - Bold & Italic:
**bold**,*italic*strong,emmarks - Inline Code:
`code`codemark - Links:
[text](url)link mark definitions - Blockquotes:
> textblockquotestyle - Unordered Lists:
- item,* itembulletlist items - Ordered Lists:
1. itemnumberlist items - Code Blocks:
```langfenced blockscodetype with language field
For complex content such as nested lists, tables, or custom Sanity schema types, verify the output in Sanity Studio after publishing.
- Select the Target Document Type: Choose the Sanity document type (e.g.,
post,article) you want to publish to from the dropdown. - (Optional) Configure Default Values for any fields in your schema that are required but not mapped (e.g., set a default
statustopublished). - Click Save Mapping.
Publishing and Workflow
Once configured, your integration is active.
- Articles in iContentForge with a status of Ready can be published individually or in bulk.
- If Drip Feed is enabled for your project, articles will be automatically published to Sanity according to your schedule (approximately every 5 minutes).
- iContentForge uses the
createOrReplacemutation if a document with the same slug already exists, it will be updated rather than duplicated. - Published articles will appear in your Sanity studio with the status
Published. - The article status in iContentForge will update from
ReadytoPublishedupon successful sync.
To troubleshoot failed publishes, check the article status log in iContentForge for error details. Common issues include schema validation errors (e.g., a required field in your Sanity schema is not mapped) or mismatched document type names.
Troubleshooting
| Issue | Likely Cause | Solution |
|---|---|---|
| Test Connection fails | Invalid Project ID, Dataset, or Token. | Double-check each credential in your Sanity Manage dashboard. Ensure the token has Editor role. |
| Publish fails with schema validation error | A required field in your Sanity schema is not mapped. | Open Sanity Studio and check which fields are marked required in your document type. Map those fields in the iContentForge field mapping configuration. |
| Publish fails before mutation with a type mismatch error | The mapped field type in Sanity does not match the value iContentForge is preparing. | Add or update Field Type Overrides in the connector settings so the publisher can validate and transform the value correctly before sending it. |
| Content appears as plain text | The content field is mapped to a string or text type instead of Portable Text. | Ensure the target Sanity field for article content is an array of block type. |
| Slug not recognized | Slug field expects { _type: "slug", current: "..." } format. | iContentForge automatically wraps the slug value in this object. If you see an error, ensure the Sanity field type is slug, not string. |
| Document type not found | The Document Type entered in settings doesn't match a schema type. | Check your Sanity Studio schema files (e.g., schemas/post.ts) for the exact _type name. |
Next Steps
- Learn how to automate publishing with Drip Feed Scheduling.
- Understand the different Article Statuses in the publishing pipeline.
- Explore other available CMS Integrations.