Sanity Pioneers: Get early access to betas, extra AI credits, and a direct line to the engineering team. Apply now

How to read and write to Sanity Content Lake using tokens from custom app

6 repliesLast updated: Nov 29, 2025

How do i
read
and
write
to my content lake via tokens. I am Not using Sanity Studio, but from my own application i want to read and write data. Do i have to shape my data in GRAQ way, or is it simple
JSON
object
Post
?
AI Update

Great question! You can absolutely read and write to your Content Lake from your own application without using Sanity Studio. Here's how it works:

Reading Data

For reading data, you'll use the HTTP Query API to execute GROQ queries. Yes, you do need to use GROQ (not "GRAQ") to query your content, but it's actually quite intuitive once you get started.

A basic query looks like:

GET https://<projectId>.api.sanity.io/<apiVersion>/data/query/<dataset>?query=*[_type == "post"]

You can also use parameters in your GROQ queries (prefixed with $) which is safe for user input since they're JSON literals that get substituted into the query.

Writing Data

For writing data, you'll use the Mutation API, and here's the good news: you write simple JSON objects, not GROQ! The Mutation API accepts standard JSON documents.

You have several mutation operations available:

Example JSON for creating a document:

{
  "mutations": [
    {
      "create": {
        "_type": "post",
        "title": "My Post",
        "content": "Post content here"
      }
    }
  ]
}

For drafts, prefix the ID with drafts.:

{
  "create": {
    "_id": "drafts.post-123",
    "_type": "post",
    "title": "Draft Post"
  }
}

Authentication

You'll need to create an API token in Sanity Manage:

Important security note: Never expose write tokens in frontend code! Use them only in server-side environments, API routes, or serverless functions.

Add the token to your requests via the Authorization header:

Authorization: Bearer <your-token>

Quick Summary

The Mutation API supports transactions too, so you can perform multiple operations atomically. One thing to note: when using the HTTP API directly, you're responsible for your own validation - the Studio's schema validation doesn't automatically apply at the API level.

Show original thread
6 replies

Was this answer helpful?

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Related contributions