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
Optional
params: ListenParamsOptional 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
Optional
params: ListenParamsOptional query parameters
Optional
options: ListenOptionsOptional listener options
Observable version of the Sanity client, with the same configuration as the promise-based one
Perform action operations against the configured dataset Returns a promise that resolves to the transaction result
Action operation(s) to execute
Optional
options: BaseActionOptionsAction options
Clone the client - returns a new instance
Returns the current client configuration
Reconfigure the client. Note that this mutates the current client.
Optional
newConfig: Partial<ClientConfig>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
Optional
options: 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
Optional
options: 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
Optional
options: 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 the deleted document.
Document ID to delete
Optional
options: 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 first deleted document.
An object with either an id
or query
key defining what to delete
Optional
options: BaseMutationOptionsOptions for the mutation
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.Optional
purge: booleanif true
the document history is also discarded.
Optional
options: BaseActionOptionsAdditional action options.
a promise that resolves to the transactionId
.
releaseId
will discard the draft version of the published document.Perform a GROQ-query against the configured dataset.
GROQ-query to perform
Optional
params: QueryWithoutParams | QPerform a GROQ-query against the configured dataset.
GROQ-query to perform
Optional query parameters
Optional
options: 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
Get a Sanity API URL for the data operation and path provided
Data operation (eg query
, mutate
, listen
or similar)
Optional
path: stringPath to append after the operation
Fetch a single document with the given ID.
Document ID to fetch
Optional
options: { releaseId?: string; signal?: AbortSignal; tag?: string }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
Optional
options: { signal?: AbortSignal; tag?: string }Request options
Get a Sanity API URL for the URI provided
URI/path to build URL for
Optional
canUseCdn: booleanWhether or not to allow using the API CDN for this route
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 the first mutated document.
Mutation operations to execute
Optional
options: BaseMutationOptionsMutation options
Create a new buildable patch of operations to perform
Document ID to patch
Optional
operations: 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
Optional
operations: 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
Optional
operations: PatchOperationsOptional object of patch operations to initialize the patch instance with
Patch instance - call .commit()
to perform the operations defined
Replaces an existing version document.
Version action parameters:
document
- The new document to replace the version with.releaseId
- The ID of the release where the document version is replaced.publishedId
- The ID of the published document to replace.Optional
options: 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.
Version action parameters:
document
- The new document to replace the version with.releaseId
- The ID of the release where the document version is replaced.publishedId
- The ID of the published document to replace.Optional
options: 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',
// }
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
Create a new transaction of mutations
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.Optional
options: BaseActionOptionsAdditional action options.
a promise that resolves to the transactionId
.
Clone the client with a new (partial) configuration.
Optional
newConfig: Partial<ClientConfig>New client configuration properties, shallowly merged with existing configuration
Creates a new version of a published document.
Version action parameters:
document
- The document to create as a new version (must include _type
).publishedId
- The ID of the published document being versioned.releaseId
- The ID of the release to create the version for.Optional
options: BaseActionOptionsAdditional action options.
A promise that resolves to the transactionId
.
_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({
// The document does not need to include an `_id` property since it will be generated from `publishedId` and `releaseId`
document: {_type: 'myDocument', title: 'My Document'},
publishedId: 'myDocument',
releaseId: 'myRelease',
})
// The following document will be created:
// {
// _id: 'versions.myRelease.myDocument',
// _type: 'myDocument',
// title: 'My Document',
// }
const transactionId = await client.createVersion({
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 created:
// {
// _id: 'versions.myRelease.myDocument',
// _type: 'myDocument',
// title: 'My Document',
// }
const transactionId = await client.createVersion({
document: {_type: 'myDocument', title: 'My Document'},
publishedId: 'myDocument',
})
// The following document will be created:
// {
// _id: 'drafts.myDocument',
// _type: 'myDocument',
// title: 'My Document',
// }
Creates a new version of a published document.
Version action parameters:
document
- The document to create as a new version (must include _type
).publishedId
- The ID of the published document being versioned.releaseId
- The ID of the release to create the version for.Optional
options: BaseActionOptionsAdditional action options.
A promise that resolves to the transactionId
.
_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({
// The document does not need to include an `_id` property since it will be generated from `publishedId` and `releaseId`
document: {_type: 'myDocument', title: 'My Document'},
publishedId: 'myDocument',
releaseId: 'myRelease',
})
// The following document will be created:
// {
// _id: 'versions.myRelease.myDocument',
// _type: 'myDocument',
// title: 'My Document',
// }
const transactionId = await client.createVersion({
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 created:
// {
// _id: 'versions.myRelease.myDocument',
// _type: 'myDocument',
// title: 'My Document',
// }
const transactionId = await client.createVersion({
document: {_type: 'myDocument', title: 'My Document'},
publishedId: 'myDocument',
})
// The following document will be created:
// {
// _id: 'drafts.myDocument',
// _type: 'myDocument',
// title: 'My Document',
// }
Instance properties