Comments API reference
Create, update and delete comments and reactions through the Collaboration HTTP API.
Create, update and delete comments and their reactions in the organization store that owns a resource. Reads are the query and listen endpoints, which the gateway serves from the organization store, not this service. vX is unstable and can change without notice.
Base API server URL
Dataset comments (resourceType=dataset).
https://{projectId}.api.sanity.ioVariables
- projectIdstringdefault:
"your-project-id"Project that owns the dataset.
Canvas comments (resourceType=canvas).
https://api.sanity.ioEndpoints
Query comments
/vX/collaboration/comments/queryRuns a GROQ query against the comments of a resource. The gateway serves it from the organization store, not this service, and it behaves like the standard query endpoint.
Query parameters
GROQ query over the resource’s comments. Pass each query parameter as its own
$name=<JSON value>, for example$documentId="article-1".Organization that owns the resource and its comment store.
Kind of resource the comment belongs to:
datasetfor a document in a project dataset,canvasfor a Canvas document.Id of the resource:
projectId.datasetfordataset, the canvas id forcanvas. Must not contain:.
Responses
Query comments with a request body
/vX/collaboration/comments/queryRuns a GROQ query against the comments of a resource. The gateway serves it from the organization store, not this service, and it behaves like the standard query endpoint. Use it when the query and parameters don't fit in a URL.
Query parameters
Organization that owns the resource and its comment store.
Kind of resource the comment belongs to:
datasetfor a document in a project dataset,canvasfor a Canvas document.Id of the resource:
projectId.datasetfordataset, the canvas id forcanvas. Must not contain:.
Responses
Listen for comment changes
/vX/collaboration/comments/listenStreams changes to the comments a GROQ query matches, as server-sent events. The gateway serves it from the organization store, not this service, and it behaves like the standard listen endpoint, including its options such as includeResult and visibility.
Query parameters
GROQ query over the resource’s comments. Pass each query parameter as its own
$name=<JSON value>, for example$documentId="article-1".Organization that owns the resource and its comment store.
Kind of resource the comment belongs to:
datasetfor a document in a project dataset,canvasfor a Canvas document.Id of the resource:
projectId.datasetfordataset, the canvas id forcanvas. Must not contain:.
Responses
An event stream of welcome, mutation and other listen events.
- string
Create a comment
/vX/collaboration/commentsCreates a top-level comment on target, or a reply when parentCommentId is set. A reply inherits its parent’s target, status and threadId, so don’t send target or threadId with it. Replies to a reply are rejected with 400. Top-level comments start as open.
Query parameters
Kind of resource the comment belongs to:
datasetfor a document in a project dataset,canvasfor a Canvas document.Id of the resource:
projectId.datasetfordataset, the canvas id forcanvas. Must not contain:.Organization that owns the resource and its comment store.
- transactionIdstring
Transaction id for the store mutation. Set it to recognize your own write when it comes back through a listener.
- clientVersionstring
Version of the calling
@sanity/client, for telemetry.
Request body application/json
- _idstring
_idfor the comment. Server-generated if omitted. - targetobject
What the comment targets. Required when
parentCommentIdis not set.Show child attributes
Id of the document the comment is on, for example
drafts.article-1, without the resource prefix. Must not contain:._typeof that document.- documentRevisionIdstring
Revision of the document the comment was written against.
- pathstring
Field the comment is on, for example
body. Required withanchor. Omit it for a document-level comment. Where in
paththe comment is anchored.Show child attributes
- fieldValuearray
Portable Text covering the anchor (at least from start to end
_key). When set, resolves the selection without fetching the source document. The full field also works.
- null
- rangedeprecated
Deprecated, use
anchor. Deprecated, use
anchor.fieldValue.
- parentCommentIdstring
When set, creates a reply to this comment.
- threadIdstring
threadIdfor a top-level comment. Server-generated if omitted. Not allowed on replies — replies inherit the parent'sthreadId. Comment body as Portable Text.
- contextobject
Free-form metadata stored as-is on the comment.
Responses
The mutation result: transactionId and one results entry per document changed (a thread change includes every reply).
The request is invalid: it failed schema validation or breaks a rule such as replying to a reply. message says which.
- codestring
Machine-readable error code, when there is one.
Missing, invalid or expired bearer token.
- codestring
Machine-readable error code, when there is one.
The token’s user can’t write comments on this resource.
- codestring
Machine-readable error code, when there is one.
The comment or resource was not found, or the resource is not in the organization.
- codestring
Machine-readable error code, when there is one.
The organization store or a dependency isn’t available yet. Retry later.
- codestring
Machine-readable error code, when there is one.
Delete a comment and all its replies
/vX/collaboration/comments/{id}Deletes the comment and its replies in one mutation. Idempotent: deleting a comment that doesn’t exist returns 200 with empty results, not 404.
Path parameters
_idof the comment.
Query parameters
Kind of resource the comment belongs to:
datasetfor a document in a project dataset,canvasfor a Canvas document.Id of the resource:
projectId.datasetfordataset, the canvas id forcanvas. Must not contain:.Organization that owns the resource and its comment store.
- transactionIdstring
Transaction id for the store mutation. Set it to recognize your own write when it comes back through a listener.
- clientVersionstring
Version of the calling
@sanity/client, for telemetry.
Responses
The mutation result: transactionId and one results entry per document changed (a thread change includes every reply).
The request is invalid: it failed schema validation or breaks a rule such as replying to a reply. message says which.
- codestring
Machine-readable error code, when there is one.
Missing, invalid or expired bearer token.
- codestring
Machine-readable error code, when there is one.
The token’s user can’t write comments on this resource.
- codestring
Machine-readable error code, when there is one.
The resource was not found or is not in the organization. A missing comment is not a 404.
- codestring
Machine-readable error code, when there is one.
The organization store or a dependency isn’t available yet. Retry later.
- codestring
Machine-readable error code, when there is one.
Update a comment
/vX/collaboration/comments/{id}Changes the message, status or anchor. status and anchor apply to the whole thread: the comment and all its replies change in one mutation. Editing message sets lastEditedAt. Only top-level comments that target a field can be anchored.
Path parameters
_idof the comment.
Query parameters
Kind of resource the comment belongs to:
datasetfor a document in a project dataset,canvasfor a Canvas document.Id of the resource:
projectId.datasetfordataset, the canvas id forcanvas. Must not contain:.Organization that owns the resource and its comment store.
- transactionIdstring
Transaction id for the store mutation. Set it to recognize your own write when it comes back through a listener.
- clientVersionstring
Version of the calling
@sanity/client, for telemetry.
Request body application/json
- messagearray
New comment body as Portable Text. Sets
lastEditedAt. - statusstring
openorresolved. Applies to the whole thread. Where in
paththe comment is anchored, as on create.nullremoves the anchor, leaving a field-level comment.Show child attributes
- fieldValuearray
Portable Text covering the anchor (at least from start to end
_key). When set, resolves the selection without fetching the source document. The full field also works.
- null
- rangedeprecated
Deprecated, use
anchor. Deprecated, use
anchor.fieldValue.
Responses
The mutation result: transactionId and one results entry per document changed (a thread change includes every reply).
The request is invalid: it failed schema validation or breaks a rule such as replying to a reply. message says which.
- codestring
Machine-readable error code, when there is one.
Missing, invalid or expired bearer token.
- codestring
Machine-readable error code, when there is one.
The token’s user can’t write comments on this resource.
- codestring
Machine-readable error code, when there is one.
The comment or resource was not found, or the resource is not in the organization.
- codestring
Machine-readable error code, when there is one.
The organization store or a dependency isn’t available yet. Retry later.
- codestring
Machine-readable error code, when there is one.
Add a reaction to a comment
/vX/collaboration/comments/{id}/reactionsAdds the token user’s reaction. Idempotent per user and reaction: adding the same reaction again replaces it rather than adding a second one.
Path parameters
_idof the comment.
Query parameters
Kind of resource the comment belongs to:
datasetfor a document in a project dataset,canvasfor a Canvas document.Id of the resource:
projectId.datasetfordataset, the canvas id forcanvas. Must not contain:.Organization that owns the resource and its comment store.
- transactionIdstring
Transaction id for the store mutation. Set it to recognize your own write when it comes back through a listener.
- clientVersionstring
Version of the calling
@sanity/client, for telemetry.
Request body application/json
Reaction to add.
Responses
The mutation result: transactionId and one results entry per document changed (a thread change includes every reply).
The request is invalid: it failed schema validation or breaks a rule such as replying to a reply. message says which.
- codestring
Machine-readable error code, when there is one.
Missing, invalid or expired bearer token.
- codestring
Machine-readable error code, when there is one.
The token’s user can’t write comments on this resource.
- codestring
Machine-readable error code, when there is one.
The comment or resource was not found, or the resource is not in the organization.
- codestring
Machine-readable error code, when there is one.
The organization store or a dependency isn’t available yet. Retry later.
- codestring
Machine-readable error code, when there is one.
Remove a reaction from a comment
/vX/collaboration/comments/{id}/reactions/{shortName}Removes the token user’s reaction.
Query parameters
Kind of resource the comment belongs to:
datasetfor a document in a project dataset,canvasfor a Canvas document.Id of the resource:
projectId.datasetfordataset, the canvas id forcanvas. Must not contain:.Organization that owns the resource and its comment store.
- transactionIdstring
Transaction id for the store mutation. Set it to recognize your own write when it comes back through a listener.
- clientVersionstring
Version of the calling
@sanity/client, for telemetry.
Responses
The mutation result: transactionId and one results entry per document changed (a thread change includes every reply).
The request is invalid: it failed schema validation or breaks a rule such as replying to a reply. message says which.
- codestring
Machine-readable error code, when there is one.
Missing, invalid or expired bearer token.
- codestring
Machine-readable error code, when there is one.
The token’s user can’t write comments on this resource.
- codestring
Machine-readable error code, when there is one.
The comment or resource was not found, or the resource is not in the organization.
- codestring
Machine-readable error code, when there is one.
The organization store or a dependency isn’t available yet. Retry later.
- codestring
Machine-readable error code, when there is one.