Observable version of the Sanity client, with the same configuration as the promise-based one
Create and manage content releases and their scheduled publishing
An archive action removes an active release. The documents that comprise the release are deleted and therefore no longer queryable.
While the documents remain in retention the last version can still be accessed using document history endpoint.
Release action parameters:
releaseId - The id of the release to archive.Optionaloptions: BaseActionOptionsAdditional action options.
A promise that resolves to the transactionId.
Creates a new release under the given id, with metadata.
Additional action options.
A promise that resolves to the transactionId and the release id and metadata.
undecided releaseType will be used.const releaseId = 'my-release'
const releaseMetadata: ReleaseDocument['metadata'] = {
releaseType: 'asap',
}
const result =
await client.releases.create({releaseId, metadata: releaseMetadata})
console.log(result)
// {
// transactionId: 'transaction-id',
// releaseId: 'my-release',
// metadata: {releaseType: 'asap'},
// }
Creates a new release under the given id, with metadata.
Optionaloptions: BaseActionOptionsAdditional action options.
A promise that resolves to the transactionId and the release id and metadata.
undecided releaseType will be used.const releaseId = 'my-release'
const releaseMetadata: ReleaseDocument['metadata'] = {
releaseType: 'asap',
}
const result =
await client.releases.create({releaseId, metadata: releaseMetadata})
console.log(result)
// {
// transactionId: 'transaction-id',
// releaseId: 'my-release',
// metadata: {releaseType: 'asap'},
// }
A delete action removes a published or archived release. The backing system document will be removed from the dataset.
Release action parameters:
releaseId - The id of the release to delete.Optionaloptions: BaseActionOptionsAdditional action options.
A promise that resolves to the transactionId.
Edits an existing release, updating the metadata.
Release action parameters:
releaseId - The id of the release to edit.patch - The patch operation to apply on the release metadata PatchMutationOperation.Optionaloptions: BaseActionOptionsAdditional action options.
A promise that resolves to the transactionId.
Fetch the documents in a release by release id.
Release action parameters:
releaseId - The id of the release to fetch documents for.Optionaloptions: BaseMutationOptionsAdditional mutation options BaseMutationOptions.
A promise that resolves to the documents in the release.
Retrieve a release by id.
Release action parameters:
releaseId - The id of the release to retrieve.Optionaloptions: { signal?: AbortSignal; tag?: string }Additional query options including abort signal and query tag.
A promise that resolves to the release document ReleaseDocument.
Publishes all documents in a release at once. For larger releases the effect of the publish
will be visible immediately when querying but the removal of the versions.<releasesId>.*
documents and creation of the corresponding published documents with the new content may
take some time.
During this period both the source and target documents are locked and cannot be modified through any other means.
Release action parameters:
releaseId - The id of the release to publish.Optionaloptions: BaseActionOptionsAdditional action options.
A promise that resolves to the transactionId.
A schedule action queues a release for publishing at the given future time. The release is locked such that no documents in the release can be modified and no documents that it references can be deleted as this would make the publish fail. At the given time, the same logic as for the publish action is triggered.
Release action parameters:
releaseId - The id of the release to schedule.publishAt - The serialised date and time to publish the release. If the publishAt is in the past, the release will be published immediately.Optionaloptions: BaseActionOptionsAdditional action options.
A promise that resolves to the transactionId.
An unarchive action restores an archived release and all documents with the content they had just prior to archiving.
Release action parameters:
releaseId - The id of the release to unarchive.Optionaloptions: BaseActionOptionsAdditional action options.
A promise that resolves to the transactionId.
An unschedule action stops a release from being published. The documents in the release are considered unlocked and can be edited again. This may fail if another release is scheduled to be published after this one and has a reference to a document created by this one.
Release action parameters:
releaseId - The id of the release to unschedule.Optionaloptions: BaseActionOptionsAdditional action options.
A promise that resolves to the transactionId.
Upload, fetch and delete assets (images and files) in the configured dataset
Uploads a file asset to the configured dataset
Note: when the client is configured against a Media Library
(resource: {type: 'media-library', id}), this resolves to a
MediaLibraryAssetDocument at runtime, not to a
SanityAssetDocument. The declared type cannot express that: the
shape depends on the client's configuration rather than on the arguments,
so an overload cannot discriminate it, and widening the return type into a
union would be a breaking change for every existing caller. Narrow the
result yourself (for example, check for currentVersion) if you upload to
a Media Library. Typing this honestly is deferred to the next major.
Asset type (file)
Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
Optionaloptions: UploadClientConfigOptions to use for the upload
Uploads an image asset to the configured dataset
Note: against a Media Library this resolves to a
MediaLibraryAssetDocument at runtime. See the 'file' overload
above for why the declared type cannot say so.
Asset type (image)
Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
Optionaloptions: UploadClientConfigOptions to use for the upload
Uploads a file or an image asset to the configured dataset
Asset type (file/image)
Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
Optionaloptions: UploadClientConfigOptions to use for the upload
Interact with Media Library assets
Upload and manage Media Library video assets
Get video playback information for a media library asset
Asset instance identifier (GDR, video-prefixed ID, or container ID)
Options for transformations and expiration
Run Agent Actions - AI-powered operations to generate, transform, translate, prompt and patch documents
Run individual Agent Action operations
Run an instruction to generate content in a target document.
instruction request
Patch a document using a schema aware API. Does not use an LLM, but uses the schema to ensure paths and values matches the schema.
instruction request
Run a raw instruction and return the result either as text or json
prompt request
Transform a target document based on a source.
translation request
Translate a target document based on a source.
translation request
Listen to document changes matching a GROQ query, delivered as server-sent events
Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
GROQ-filter to listen to changes for
Optionalparams: ClientParams<G, ListenParams> | QueryWithoutParamsOptional query parameters
Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
GROQ-filter to listen to changes for
Optionalparams: QueryWithoutParams | ClientParams<G, ListenParams>Optional query parameters
Optionaloptions: OptsOptional listener options
Subscribe to live content updates through the Live Content API
Requires apiVersion to be 2021-03-25 or later.
OptionalincludeDrafts?: booleanOptionaltag?: stringOptional request tag for the listener. Use to identify the request in logs.
OptionalwaitFor?: "function"Delays events until after a Sanity Function has processed them and called the callback endpoint. When omitted, events are delivered immediately.
Create, list, edit and delete datasets in the configured project
Create a new dataset with the given name
Name of the dataset to create
Optionaloptions: DatasetCreateOptionsOptions for the dataset, including optional embeddings configuration
Delete a dataset with the given name
Name of the dataset to delete
Edit a dataset with the given name
Name of the dataset to edit
Optionaloptions: DatasetEditOptionsNew options for the dataset
Edit embeddings settings for a dataset
Name of the dataset
Embeddings settings to apply
Get embeddings settings for a dataset
Name of the dataset
Fetch a list of datasets for the configured project
Fetch information about the projects the authenticated user has access to
Fetch a project by project ID
ID of the project to fetch
Fetch a list of projects the authenticated user has access to.
Optionaloptions: TOptions for the list request
includeMembers - Whether to include members in the response (default: true)includeFeatures - Whether to include features in the response (default: true)organizationId - ID of the organization to fetch projects foronlyExplicitMembership - Whether to include only projects with explicit membership (default: false)Fetch information about users in the configured project
Fetch a user by user ID
User ID of the user to fetch. If me is provided, a minimal response including the users role is returned.
Clone the client - returns a new instance
Returns the current client configuration
Reconfigure the client. Note that this mutates the current client.
OptionalnewConfig: Partial<ClientConfig>Clone the client with a new (partial) configuration.
OptionalnewConfig: Partial<ClientConfig>New client configuration properties, shallowly merged with existing configuration
Convenient and bandwidth efficient method of checking wether a set of document IDs exists. Returns a set of the IDs that exist.
Document IDs to check
Optionaloptions: { signal?: AbortSignal; tag?: string }Request options
Perform a GROQ-query against the configured dataset.
GROQ-query to perform
Optionalparams: QueryWithoutParams | QPerform a GROQ-query against the configured dataset.
GROQ-query to perform
Optional query parameters
Optionaloptions: FilteredResponseQueryOptionsOptional request options
Perform a GROQ-query against the configured dataset.
GROQ-query to perform
Optional query parameters
Request options
Perform a GROQ-query against the configured dataset.
GROQ-query to perform
Optional query parameters
Request options
Fetch a single document with the given ID.
Document ID to fetch
Request options
Fetch a single document with the given ID.
Document ID to fetch
Optionaloptions: {Request options
Fetch multiple documents in one request.
Should be used sparingly - performing a query is usually a better option.
The order/position of documents is preserved based on the original array of IDs.
If any of the documents are missing, they will be replaced by a null entry in the returned array
Document IDs to fetch
Optionaloptions: { signal?: AbortSignal; tag?: string }Request options
Create a document. Requires a _type property. If no _id is provided, it will be generated by the database.
Returns a promise that resolves to the created document.
Document to create
Mutation options
Create a document. Requires a _type property. If no _id is provided, it will be generated by the database.
Returns a promise that resolves to an array containing the created document.
Document to create
Mutation options
Create a document. Requires a _type property. If no _id is provided, it will be generated by the database.
Returns a promise that resolves to a mutation result object containing the ID of the created document.
Document to create
Mutation options
Create a document. Requires a _type property. If no _id is provided, it will be generated by the database.
Returns a promise that resolves to a mutation result object containing the ID of the created document.
Document to create
Mutation options
Create a document. Requires a _type property. If no _id is provided, it will be generated by the database.
Returns a promise that resolves to the created document.
Document to create
Optionaloptions: BaseMutationOptionsMutation options
Create a document if no document with the same ID already exists. Returns a promise that resolves to the created document.
Document to create
Mutation options
Create a document if no document with the same ID already exists. Returns a promise that resolves to an array containing the created document.
Document to create
Mutation options
Create a document if no document with the same ID already exists. Returns a promise that resolves to a mutation result object containing the ID of the created document.
Document to create
Mutation options
Create a document if no document with the same ID already exists. Returns a promise that resolves to a mutation result object containing the ID of the created document.
Document to create
Mutation options
Create a document if no document with the same ID already exists. Returns a promise that resolves to the created document.
Document to create
Optionaloptions: BaseMutationOptionsMutation options
Create a document if it does not exist, or replace a document with the same document ID Returns a promise that resolves to the created document.
Document to either create or replace
Mutation options
Create a document if it does not exist, or replace a document with the same document ID Returns a promise that resolves to an array containing the created document.
Document to either create or replace
Mutation options
Create a document if it does not exist, or replace a document with the same document ID Returns a promise that resolves to a mutation result object containing the ID of the created document.
Document to either create or replace
Mutation options
Create a document if it does not exist, or replace a document with the same document ID Returns a promise that resolves to a mutation result object containing the created document ID.
Document to either create or replace
Mutation options
Create a document if it does not exist, or replace a document with the same document ID Returns a promise that resolves to the created document.
Document to either create or replace
Optionaloptions: BaseMutationOptionsMutation options
Deletes a document with the given document ID. Returns a promise that resolves to the deleted document.
Document ID to delete
Options for the mutation
Deletes a document with the given document ID. Returns a promise that resolves to an array containing the deleted document.
Document ID to delete
Options for the mutation
Deletes a document with the given document ID. Returns a promise that resolves to a mutation result object containing the deleted document ID.
Document ID to delete
Options for the mutation
Deletes a document with the given document ID. Returns a promise that resolves to a mutation result object containing the deleted document ID.
Document ID to delete
Options for the mutation
Deletes a document with the given document ID. Returns a promise that resolves to a mutation result object containing the deleted document ID.
Document ID to delete
Optionaloptions: BaseMutationOptionsOptions for the mutation
Deletes one or more documents matching the given query or document ID. Returns a promise that resolves to first deleted document.
An object with either an id or query key defining what to delete
Options for the mutation
Deletes one or more documents matching the given query or document ID. Returns a promise that resolves to an array containing the deleted documents.
An object with either an id or query key defining what to delete
Options for the mutation
Deletes one or more documents matching the given query or document ID. Returns a promise that resolves to a mutation result object containing the ID of the first deleted document.
An object with either an id or query key defining what to delete
Options for the mutation
Deletes one or more documents matching the given query or document ID. Returns a promise that resolves to a mutation result object containing the document IDs that were deleted.
An object with either an id or query key defining what to delete
Options for the mutation
Deletes one or more documents matching the given query or document ID. Returns a promise that resolves to a mutation result object containing the document IDs that were deleted.
An object with either an id or query key defining what to delete
Optionaloptions: BaseMutationOptionsOptions for the mutation
Perform mutation operations against the configured dataset Returns a promise that resolves to the first mutated document.
Mutation operations to execute
Mutation options
Perform mutation operations against the configured dataset. Returns a promise that resolves to an array of the mutated documents.
Mutation operations to execute
Mutation options
Perform mutation operations against the configured dataset Returns a promise that resolves to a mutation result object containing the document ID of the first mutated document.
Mutation operations to execute
Mutation options
Perform mutation operations against the configured dataset Returns a promise that resolves to a mutation result object containing the mutated document IDs.
Mutation operations to execute
Mutation options
Perform mutation operations against the configured dataset Returns a promise that resolves to a mutation result object containing the mutated document IDs.
Mutation operations to execute
Optionaloptions: BaseMutationOptionsMutation options
Create a new buildable patch of operations to perform
Document ID to patch
Optionaloperations: PatchOperationsOptional object of patch operations to initialize the patch instance with
Patch instance - call .commit() to perform the operations defined
Create a new buildable patch of operations to perform
Array of document IDs to patch
Optionaloperations: PatchOperationsOptional object of patch operations to initialize the patch instance with
Patch instance - call .commit() to perform the operations defined
Create a new buildable patch of operations to perform
An object with query and optional params, defining which document(s) to patch
Optionaloperations: PatchOperationsOptional object of patch operations to initialize the patch instance with
Patch instance - call .commit() to perform the operations defined
Create a new transaction of mutations
Creates a new version of a published document.
Optionaloptions: BaseActionOptionsAdditional action options.
A promise that resolves to the transactionId.
baseId to refer to the existing published document, but it is also possible to provide a complete document instead.document is provided, it must have a _type property.releaseId will create a new draft version of the published document.document._id is defined, it should be a draft or release version ID that matches the version ID generated from publishedId and releaseId.document._id is not defined, it will be generated from publishedId and releaseId.client.create method.const transactionId = await client.createVersion({
baseId: 'myDocument',
publishedId: 'myDocument',
releaseId: 'myRelease',
})
// The following document will be created:
// {
// _id: 'versions.myRelease.myDocument',
// _type: 'myDocument',
// title: 'My Document',
// }
Creates a new version of a published document.
Optionaloptions: BaseActionOptionsAdditional action options.
A promise that resolves to the transactionId.
baseId to refer to the existing published document, but it is also possible to provide a complete document instead.document is provided, it must have a _type property.releaseId will create a new draft version of the published document.document._id is defined, it should be a draft or release version ID that matches the version ID generated from publishedId and releaseId.document._id is not defined, it will be generated from publishedId and releaseId.client.create method.const transactionId = await client.createVersion({
baseId: 'myDocument',
publishedId: 'myDocument',
releaseId: 'myRelease',
})
// The following document will be created:
// {
// _id: 'versions.myRelease.myDocument',
// _type: 'myDocument',
// title: 'My Document',
// }
Creates a new version of a published document.
Optionaloptions: BaseActionOptionsAdditional action options.
A promise that resolves to the transactionId.
baseId to refer to the existing published document, but it is also possible to provide a complete document instead.document is provided, it must have a _type property.releaseId will create a new draft version of the published document.document._id is defined, it should be a draft or release version ID that matches the version ID generated from publishedId and releaseId.document._id is not defined, it will be generated from publishedId and releaseId.client.create method.const transactionId = await client.createVersion({
baseId: 'myDocument',
publishedId: 'myDocument',
releaseId: 'myRelease',
})
// The following document will be created:
// {
// _id: 'versions.myRelease.myDocument',
// _type: 'myDocument',
// title: 'My Document',
// }
Deletes the draft or release version of a document.
Version action parameters:
releaseId - The ID of the release to discard the document from.publishedId - The published ID of the document to discard.Optionalpurge: booleanif true the document history is also discarded.
Optionaloptions: BaseActionOptionsAdditional action options.
a promise that resolves to the transactionId.
releaseId will discard the draft version of the published document.Replaces an existing version document.
Optionaloptions: BaseActionOptionsAdditional action options.
a promise that resolves to the transactionId.
_type property.document._id is defined, it should be a draft or release version ID that matches the version ID generated from publishedId and releaseId.document._id is not defined, it will be generated from publishedId and releaseId.releaseId will replace the draft version of the published document.await client.replaceVersion({
document: {_type: 'myDocument', title: 'My Document'},
publishedId: 'myDocument',
releaseId: 'myRelease',
})
// The following document will be patched:
// {
// _id: 'versions.myRelease.myDocument',
// _type: 'myDocument',
// title: 'My Document',
// }
await client.replaceVersion({
document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
// `publishedId` and `releaseId` are not required since `document._id` has been specified
})
// The following document will be patched:
// {
// _id: 'versions.myRelease.myDocument',
// _type: 'myDocument',
// title: 'My Document',
// }
Replaces an existing version document.
Optionaloptions: BaseActionOptionsAdditional action options.
a promise that resolves to the transactionId.
_type property.document._id is defined, it should be a draft or release version ID that matches the version ID generated from publishedId and releaseId.document._id is not defined, it will be generated from publishedId and releaseId.releaseId will replace the draft version of the published document.await client.replaceVersion({
document: {_type: 'myDocument', title: 'My Document'},
publishedId: 'myDocument',
releaseId: 'myRelease',
})
// The following document will be patched:
// {
// _id: 'versions.myRelease.myDocument',
// _type: 'myDocument',
// title: 'My Document',
// }
await client.replaceVersion({
document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
// `publishedId` and `releaseId` are not required since `document._id` has been specified
})
// The following document will be patched:
// {
// _id: 'versions.myRelease.myDocument',
// _type: 'myDocument',
// title: 'My Document',
// }
Used to indicate when a document within a release should be unpublished when the release is run.
Version action parameters:
releaseId - The ID of the release to unpublish the document from.publishedId - The published ID of the document to unpublish.Optionaloptions: BaseActionOptionsAdditional action options.
a promise that resolves to the transactionId.
Get a Sanity API URL for the data operation and path provided
Data operation (eg query, mutate, listen or similar)
Optionalpath: stringPath to append after the operation
Get a Sanity API URL for the URI provided
URI/path to build URL for
OptionalcanUseCdn: booleanWhether or not to allow using the API CDN for this route
Perform a request against the Sanity API NOTE: Only use this for Sanity API endpoints, not for your own APIs!
Request options
Promise resolving to the response body
Deprecated
-- Use
import {SanityClient} from '@sanity/client'instead