Doc API reference
Retrieve one or more documents by ID and bypass the caching layer.
The Doc API bypasses caching, so every request goes to the backend. To fetch content in most cases, use the Query API instead.
Authentication
Requests to a public dataset don't need a token, but they return only published documents. To read drafts, release versions, or any document in a private dataset, authenticate requests with a token that has read access to those documents. Documents the request can't read aren't returned. Instead, the response lists their IDs in omitted with the reason permission.
Base API server URL
Sanity API base URL
https://{projectId}.api.sanity.io/{apiVersion}Variables
- projectIdstringdefault:
"projectId"Sanity project ID
- apiVersionstringdefault:
"v2025-02-19"API version
Endpoints
Get one or more documents
/data/doc/{dataset}/{documentId}Returns the latest version of one or more documents by ID, without the delay of the query index. It is less scalable than the Query API, so use it only when you need the most recent write.
The endpoint accepts only the query parameters listed here. Any other parameter, including perspective, returns a 400 error.
Path parameters
Comma-separated list of document IDs. IDs aren't validated beyond UTF-8 encoding, so an ID that doesn't match any document is listed in
omittedwith the reasonexistence.Example["my-doc","drafts.my-doc"]items
- itemsstring
Query parameters
If true, also return the draft and every release version of each published document ID you request. This only applies to published IDs: a draft or version ID returns only that document. Drafts and release versions are returned even if the published document doesn't exist, in which case the published ID is also listed in
omittedwith the reasonexistence.The parameter can be passed without a value (
?includeAllVersions), which is the same astrue.Requires API version v2025-02-19 or later. Earlier API versions reject the parameter with a
400error.If true, return
documentsasnulland return onlyomitted. Use this to check whether documents exist without fetching their content. The parameter requires a value:?excludeContentwithout one returns a400error.- tagstring
A tag to identify the request in logs. Can be passed only once.
Responses
Returns a list of matching documents. Document shape matches a Sanity document and includes all non-null fields.
Invalid request. Returned for:
- A document ID that isn't valid UTF-8 (
invalid UTF-8 in ID: …). - A non-boolean
excludeContentorincludeAllVersionsvalue (invalid excludeContent specified: …,invalid includeAllVersions specified: …). - An unsupported query parameter (
Unknown query parameter "…"), includingincludeAllVersionson API versions earlier than v2025-02-19. tagpassed more than once (tag can only occur once).
The dataset doesn't exist.