Actions API reference
Reference documentation for the Actions HTTP endpoint.
The Actions API is a higher-level alternative to the Mutations API. It is used by Sanity Studio in the course of regular authoring workflows, but can also be used directly. All requests must be authenticated.
Authentication
- All requests must be authenticated.
- Manipulating documents requires read and write access permission for the affected document type. In most cases, this includes the Editor, Developer, or Administrator roles.
Action types
Actions are identified by their actionType. For a complete list of properties to supply to each action, select the action type in the actions property of the request body.
Document actions
Document actions use an actionType that begins with sanity.action.document.
Most of the action types take a versionId, referring to the draft or release version, and a publishedId, referring to the published version of the document.
The versionId must have either drafts. or versions.<release>. as a prefix, and the portion following that prefix must match publishedId.
sanity.action.document.create: Creates a new document in the dataset.sanity.action.document.delete: Deletes a document from the dataset.sanity.action.document.edit: Modifies an existing document using a patch.sanity.action.document.publish: Publishes a document, making it available in the published perspective.sanity.action.document.unpublish: Unpublishes a document, removing it from the published perspective.sanity.action.document.discard: [DEPRECATED] Discards a document (use version actions instead).sanity.action.document.replaceDraft: [DEPRECATED] Replaces a draft document (use version actions instead).
Version actions
Version actions use an actionType starting with sanity.action.document.version.
These actions operate solely on the versions of documents. They follow the same authoring model as sanity.action.document actions by requiring a publishedId, referring to the published version of the document. This is true even if the published version does not yet exist, such as when starting a draft or version of a new document.
sanity.action.document.version.create: Creates a new version of a document associated with a release.sanity.action.document.version.discard: Discards a version of a document, optionally purging its history.sanity.action.document.version.replace: Replaces an existing version of a document.sanity.action.document.version.unpublish: Marks a version for unpublishing when the associated release is published.
Release actions
Release actions use an actionType starting with sanity.action.release.
Use release actions to interact with Content Releases and Scheduled Drafts.
sanity.action.release.create: Creates a new release with optional metadata.sanity.action.release.edit: Modifies the metadata of an existing release.sanity.action.release.publish: Publishes all documents in a release.sanity.action.release.archive: Archives a release, removing it from active releases.sanity.action.release.unarchive: Restores an archived release to its pre-archived state.sanity.action.release.schedule: Schedules a release for publishing at a future time.sanity.action.release.unschedule: Cancels a scheduled release.sanity.action.release.delete: Deletes a published or archived release.sanity.action.release.import: Imports a release document.
You can't mix different types of actions, such as release and document actions, in a single transaction.
Base API server URL
Parameterized base URL for Sanity API endpoints
https://{projectId}.api.sanity.io/{apiVersion}Variables
- projectIdstringdefault:
"your-project-id"Your Sanity project ID. This can be found in your project settings or in the URL when accessing your project in the Sanity management interface.
- apiVersionstringdefault:
"v2025-02-19"The version of the API to use. This should match the version specified in the info.version field.
Endpoints
Dispatch one or more actions
/data/actions/{dataset}Execute one or more actions in a single transaction. Each action must specify its type and required parameters. All actions must be valid and you must have permission to perform them.
The actions are executed in the order they appear in the request. If any action fails, the entire transaction is rolled back.
Important notes:
- You cannot mix different types of actions (e.g., release and document actions) in a single API call
- Documents in a release that isn't
active(for example, while it's scheduled or publishing) are locked and cannot be modified - Release IDs can't match an existing release, including published and archived releases; an ID becomes available again once its release is deleted
- Documents remain in retention after archiving and can be accessed via the document history endpoint
Path parameters
The dataset to perform actions on. This is the name of your Sanity dataset.
Request body application/json
An array of actions to execute. Each action must specify its type and required parameters. Actions are executed in the order they appear in the array.
Show child attributes
items
Identifies this as a document creation action.
The ID of the published document. This should be the full document ID without any prefixes.
What to do if the document already exists.
The document to create. Must include
_typeand_idfields.Example{"_type":"post","_id":"drafts.post-123","title":"My First Post","slug":{"current":"my-first-post"},"body":[{"_type":"block","children":[{"_type":"span","text":"Hello world!"}]}]}
Identifies this as a document deletion action
The ID of the document to delete. This should be the full document ID without any prefixes.
- includeDraftsarray
An array of draft or version document IDs to delete alongside the published document. Each ID must be the
publishedIdwith adrafts.orversions.<release>.prefix. Before API versionv2025-02-19, only a singledrafts.ID is allowed.Show child attributes
items
- string
If true, the document history is also deleted. This cannot be undone. Requires the
editHistorypermission, which no default role grants; you need a custom role.
Identifies this as a document edit action
The ID of the document to edit. This should be the full document ID without any prefixes.
The ID of the version (or draft) to edit. This should be the full version ID.
The patch to apply to the document. Unlike a Mutations API patch, it has no
idfield; the target isversionId. Supported operations:- set: Set a field to a value
- setIfMissing: Set a field only if it isn't already present
- unset: Remove a field
- insert: Insert items into an array, before or after a position, or replace items
- inc: Increment a number
- dec: Decrement a number
- diffMatchPatch: Apply a diff-match-patch to a string
See the patch documentation for more on patches.
Identifies this as a document publish action
The ID of the document to publish. If the document is an existing draft or version, omit the
drafts.orversions.prefix.The ID of the draft to publish. This should be the full draft ID including the 'drafts.' prefix. This parameter is deprecated. Use versionId instead.
The ID of the draft or version to publish. This should be the full ID including the
drafts.orversions.<release>.prefix.- ifVersionRevisionIdstring
The expected revision of the draft or version being published. Used to optimistically lock it so it isn't changed during publishing. Fails with
409 Conflictif the revision doesn't match. Can't be combined withifDraftRevisionId. The expected revision of the draft being published. This parameter is deprecated. Use ifVersionRevisionId instead.
- ifPublishedRevisionIdstring
The expected revision of the published document. Used to optimistically lock the published document so it isn't changed by other means during publishing. Fails with
409 Conflictif the revision doesn't match.
Identifies this as a document unpublish action
The ID of the document to unpublish. This should be the full document ID without any prefixes. The published document must exist.
The ID of the draft or version that keeps the content after unpublishing. This should be the full ID including the
drafts.orversions.<release>.prefix.
Identifies this as a document discard action
The ID of the draft to discard, including the
drafts.prefix. From API versionv2025-02-19, aversions.<release>.ID is also accepted.If true, the document history is also deleted. This cannot be undone. Requires the
editHistorypermission, which no default role grants; you need a custom role.
Identifies this as a document replace draft action
The ID of the published document whose draft is being replaced. This should be the full document ID without any prefixes.
The document to replace the draft with. Must include
_idand_typefields. The_idmust start with 'drafts.'.
Identifies this as a version creation action
The ID of the published document to create a version of. This should be the full document ID without any prefixes.
- documentobject
The document to create as a version. Must include
_idand_typefields. The_idmust start with 'versions..' where is the ID of the release. If not provided, you must specify versionId and baseId to copy from an existing document. Can't be combined with versionId, baseId, or ifBaseRevisionId. - versionIdstring
The document ID to be created. Required when document is not provided. Must start with 'versions.
.' where is the ID of the release. - baseIdstring
The ID of an existing document to copy attributes from. Required when document is not provided.
- ifBaseRevisionIdstring
Optional revision ID check for the document referenced by baseId. The action fails with
409 Conflictif this does not match its current revision.
Identifies this as a version discard action
The ID of the draft or version to discard. This should be the full ID including the
drafts.orversions.<release>.prefix.If true, the document history is also deleted. This cannot be undone. Requires the
editHistorypermission, which no default role grants; you need a custom role.
Identifies this as a version replace action
The document to replace the existing version with. Must include
_idand_typefields. The_idmust start with either 'drafts.' or 'versions..'.
Identifies this as a version unpublish action
The ID of the version to unpublish. This should be the full version ID including the 'versions.
.' prefix. The ID of the published document to remove. This should be the full document ID without any prefixes. The published document must exist.
Identifies this as a release creation action
The unique ID for the release. Can't match the ID of an existing release, including published and archived releases. Once a release is deleted, its ID can be reused.
- metadataobject
Optional metadata for the release. Can include title, description, and scheduling information. Metadata is free-form: the API stores it as provided and doesn't validate these properties. The properties below are the ones Sanity Studio reads.
Show child attributes
- titlestring
A human-readable title for the release
- descriptionstring
A detailed description of the release
- releaseTypestring
The type of release, as used by Sanity Studio:
- asap: Release will be published as soon as possible
- undecided: Release timing is not yet determined
- scheduled: Release will be published at a specific time
- intendedPublishAtstring (date-time)
The intended publish time for scheduled releases. Only used when releaseType is 'scheduled'.
Identifies this as a release edit action
The ID of the release to edit. The release must exist and not be published.
The patch to apply to the release metadata. Every path must start with 'metadata'. Can include operations like set, unset, etc. Setting
metadataitself replaces the whole metadata object, so target individual properties to keep the others.- ifRevisionIDstring
Optional revision ID check for the release. The action fails with
409 Conflictif this does not match the current revision of the release. Note the uppercaseID.
Identifies this as a release publish action
The ID of the release to publish. The release must exist and be in the
activestate.- ifRevisionIDstring
Optional revision ID check for the release. The action fails with
409 Conflictif this does not match the current revision of the release. Note the uppercaseID.
Identifies this as a release archive action
The ID of the release to archive. The release must exist and be in the
activestate.- ifRevisionIDstring
Optional revision ID check for the release. The action fails with
409 Conflictif this does not match the current revision of the release. Note the uppercaseID.
Identifies this as a release unarchive action
The ID of the release to unarchive. The release must exist and be archived.
- ifRevisionIDstring
Optional revision ID check for the release. The action fails with
409 Conflictif this does not match the current revision of the release. Note the uppercaseID.
Identifies this as a release schedule action
The ID of the release to schedule. The release must exist and be in the
activestate.The time to publish the release. A time in the past isn't rejected; the release is published right away.
- ifRevisionIDstring
Optional revision ID check for the release. The action fails with
409 Conflictif this does not match the current revision of the release. Note the uppercaseID.
Identifies this as a release unschedule action
The ID of the release to unschedule. The release must exist and be scheduled.
- ifRevisionIDstring
Optional revision ID check for the release. The action fails with
409 Conflictif this does not match the current revision of the release. Note the uppercaseID.
Identifies this as a release delete action
The ID of the release to delete. The release must exist and be either published or archived.
- ifRevisionIDstring
Optional revision ID check for the release. The action fails with
409 Conflictif this does not match the current revision of the release. Note the uppercaseID.
Identifies this as a release import action
The ID of the release to import.
The release document.
What to do if the release already exists: fail with
409 Conflict, leave the existing release unchanged, or replace it.
If true, the actions will be executed but the results will not be saved.
If true then any cross-dataset references will be considered weak for the purposes of this request.
- transactionIdstring
By default every transaction gets a random ID. This is included in Listener mutation events and the History API. This parameter lets you set your own transaction ID. It must be unique in the dataset; reusing an ID fails with
409 Conflict.
application/jsonDemonstrates how to create a new document of type "post" with a specific ID using the document create action.
{
"actions": [
{
"actionType": "sanity.action.document.create",
"publishedId": "post-123",
"document": {
"_type": "post",
"_id": "drafts.post-123"
}
}
]
}Shows how to delete a document by its published ID, including any associated drafts or version documents.
{
"actions": [
{
"actionType": "sanity.action.document.delete",
"publishedId": "post-123",
"includeDrafts": [
"drafts.post-123",
"versions.spring-2024.post-123"
]
}
]
}Demonstrates editing an existing document by applying a patch to a specific version.
{
"actions": [
{
"actionType": "sanity.action.document.edit",
"publishedId": "post-123",
"versionId": "versions.spring-2024.post-123",
"patch": {
"set": {
"title": "Updated Title",
"slug.current": "updated-title"
}
}
}
]
}Publishes a specific version of a document, replacing the published document with its content.
{
"actions": [
{
"actionType": "sanity.action.document.publish",
"publishedId": "post-123",
"versionId": "versions.spring-2024.post-123"
}
]
}Unpublishes a document by deleting the published document, keeping its content in the given draft or version.
{
"actions": [
{
"actionType": "sanity.action.document.unpublish",
"publishedId": "post-123",
"versionId": "versions.spring-2024.post-123"
}
]
}Creates a new version of a document in a release by providing the full document object.
{
"actions": [
{
"actionType": "sanity.action.document.version.create",
"publishedId": "post-123",
"document": {
"_id": "versions.spring-2024.post-123",
"_type": "post",
"title": "New Version Post",
"slug": {
"current": "new-version-post"
}
}
}
]
}Creates a new version by copying attributes from an existing document, optionally checking a base revision ID.
{
"actions": [
{
"actionType": "sanity.action.document.version.create",
"publishedId": "post-123",
"versionId": "versions.spring-2024.post-123",
"baseId": "drafts.post-123",
"ifBaseRevisionId": "abc123"
}
]
}Discards a specific version of a document, optionally purging its history from the dataset.
{
"actions": [
{
"actionType": "sanity.action.document.version.discard",
"versionId": "versions.radiant.foo",
"purge": true
}
]
}Replaces an existing version of a document with a new document object, updating its content.
{
"actions": [
{
"actionType": "sanity.action.document.version.replace",
"document": {
"_id": "versions.radiant.foo",
"_type": "fooType",
"bar": 1,
"qux": 2
}
}
]
}Marks a version for unpublishing so that when the release is published, the published document will be removed.
{
"actions": [
{
"actionType": "sanity.action.document.version.unpublish",
"versionId": "versions.radiant.foo",
"publishedId": "foo"
}
]
}Demonstrates how to create a new release with metadata, such as a title, using the release create action.
{
"actions": [
{
"actionType": "sanity.action.release.create",
"releaseId": "radiant",
"metadata": {
"title": "An important release"
}
}
]
}Shows how to edit the metadata of an existing release using a patch operation.
{
"actions": [
{
"actionType": "sanity.action.release.edit",
"releaseId": "radiant",
"patch": {
"set": {
"metadata.title": "An even more important release"
}
}
}
]
}Publishes all documents in a release, replacing the published documents with the release content.
{
"actions": [
{
"actionType": "sanity.action.release.publish",
"releaseId": "radiant"
}
]
}Archives a release, removing it from active releases but retaining its documents in retention.
{
"actions": [
{
"actionType": "sanity.action.release.archive",
"releaseId": "radiant"
}
]
}Restores an archived release to its pre-archived state, making it active again.
{
"actions": [
{
"actionType": "sanity.action.release.unarchive",
"releaseId": "radiant"
}
]
}Schedules a release to be published at a specific future time, locking the release until then.
{
"actions": [
{
"actionType": "sanity.action.release.schedule",
"releaseId": "radiant",
"publishAt": "2024-09-23T10:12:00Z"
}
]
}Cancels a previously scheduled release, unlocking it for further edits.
{
"actions": [
{
"actionType": "sanity.action.release.unschedule",
"releaseId": "radiant"
}
]
}Deletes a published or archived release from the dataset, removing its backing system document.
{
"actions": [
{
"actionType": "sanity.action.release.delete",
"releaseId": "radiant"
}
]
}Demonstrates how to dispatch multiple actions in a single transaction. In this example, a document is edited and then published in the same request. Note that it is not permitted to mix different types of actions, such as release and document actions, in a single transaction.
{
"actions": [
{
"actionType": "sanity.action.document.edit",
"versionId": "drafts.foo",
"publishedId": "foo",
"patch": {
"set": {
"name": "Remington Steele"
}
}
},
{
"actionType": "sanity.action.document.publish",
"versionId": "drafts.foo",
"publishedId": "foo"
}
]
}[DEPRECATED] Discards a draft version of a document. Use version actions instead.
{
"actions": [
{
"actionType": "sanity.action.document.discard",
"draftId": "drafts.post-123",
"purge": true
}
]
}[DEPRECATED] Replaces a draft document with new content. Use version actions instead.
{
"actions": [
{
"actionType": "sanity.action.document.replaceDraft",
"publishedId": "post-123",
"attributes": {
"_id": "drafts.post-123",
"_type": "post",
"title": "Updated Draft Post",
"slug": {
"current": "updated-draft-post"
}
}
}
]
}Responses
The actions were successfully executed in a single transaction. Any warnings are returned in X-Sanity-Warning response headers.
- transactionIdstring
The ID of the transaction that applied the actions. It appears in Listener mutation events and the History API.
The request was invalid. This could be due to:
- Missing required fields, or fields the action doesn't recognize
- Invalid action types
- Invalid parameters for actions
- Invalid document IDs or types
- Mixing different types of actions in a single request
- Release actions sent with an API version earlier than
v2025-02-19 - A release that doesn't exist, or isn't in a state that allows the action (for example, publishing a scheduled release)
- Modifying documents in a release that is locked because it's scheduled or publishing
- Deleting a release that still contains documents
The request was not authenticated. Make sure you're using a valid API token.
The request was not authorized. Your API token doesn't have permission to perform the requested actions.
A document the action needs doesn't exist, such as the draft or version being published or discarded, or the published document being unpublished.
The whole endpoint also returns 404 Not Found for API versions earlier than v2024-05-23.
The request conflicts with the current state of the dataset. This could be due to:
- Creating a document or release that already exists
- A revision check (such as
ifVersionRevisionId,ifPublishedRevisionId,ifBaseRevisionId, orifRevisionID) that doesn't match the current revision - Deleting a published document while a draft or version exists that isn't listed in
includeDrafts - Reusing a
transactionId
An internal server error occurred. This is usually temporary and the request can be retried.