Skip to main content
The comments module provides full server-side control over comments on entities. Use it to seed content, build moderation pipelines, or integrate comment data into your backend logic.

createComment

Creates a new comment on an entity, with optional images and files.
string
required
The Sublay entity ID to comment on.
string
required
The user the service key acts as: the comment author.
string | null
The comment text content. null or an empty string stores none — a comment needs content, a gif, attachments, images or files.
string
Your application’s identifier for this comment.
object
A GIF to attach to the comment (GifData), or null.
array
User mentions embedded in the comment.
string | null
The Sublay comment ID of the parent, for creating a reply.
string
A comment being directly quoted or referenced.
array
File or media attachments on the comment.
object
Arbitrary metadata attached to the comment.
string | Date
Backdates the comment’s creation time: a Date, or a full UTC timestamp string such as "2024-03-01T12:00:00.000Z" (date.toISOString()). A string in another format (a date alone, or a time with an offset) is refused with 400 comment/invalid-body and param naming the field. More than five minutes in the future returns 400 comment/invalid-body (createdAt can't be in the future.).
string | Date
Same format as createdAt, used to backdate the comment’s last update time. More than five minutes in the future returns 400 comment/invalid-body (updatedAt can't be in the future.).
{ files: { file: Uint8Array | Blob; filename?: string; mimeType?: string }[]; options: ImageOptions }
Images on the comment, processed into sizes per options (mode is required). Pass mimeType with a Uint8Array (image/jpeg, image/png or image/webp; without it the file goes as application/octet-stream and is refused with 400 comment/unsupported-file-type); a Blob keeps its own type. A PDF goes in files: in images it isn’t a valid image (422 comment/invalid-image). With images or files, the request is sent as multipart/form-data. A request takes at most 20 files in all. Requires the files-images bundle.
{ files: { file: Uint8Array | Blob; filename?: string; mimeType?: string }[]; options?: { pathParts?: string[] } }
Files on the comment, stored as uploaded (JPEG, PNG, WebP or PDF: pass mimeType with a Uint8Array). Each file’s type comes from its MIME type; an image sent here isn’t processed, so it has no image data. Requires the files-images bundle.
Returns — Promise<Comment>. With the files-images bundle installed, the created comment carries files ([] for none). When the server refuses the comment, the call rejects with its error — among them 403 comment/parent-deleted and 403 comment/parent-removed for a reply to a deleted or removed comment, 403 comment/referenced-deleted and 403 comment/referenced-removed for a quote of one, and 409 comment/foreign-id-taken for a foreignId already in use. See Create Comment → Error Responses for the full list.

fetchComment

Fetches a single comment by its Sublay ID.
string
required
The Sublay comment ID.
string
The user to read as: you get exactly what their own access token would get (blocks, their own removed comments in full, moderation details only where they may see them). Omit it for the anonymous view, with no moderation details.
CommentIncludeParam
Associations to populate, as a single value or an array: "user", "entity", "space", "parent", "grants", "files" (the comment’s images and files; requires the files-images bundle).
Returns — Promise<Comment>

fetchCommentByForeignId

Fetches a comment by your application’s own identifier.
string
required
Your application’s comment identifier.
string
The user to read as: you get exactly what their own access token would get (blocks, their own removed comments in full, moderation details only where they may see them). Omit it for the anonymous view, with no moderation details.
CommentIncludeParam
Associations to populate, as a single value or an array: "user", "entity", "space", "parent", "grants", "files" (the comment’s images and files; requires the files-images bundle).
Returns — Promise<Comment>

updateComment

Updates the content or metadata of an existing comment, as its author.
string
required
The Sublay comment ID to update.
string
The new comment text. Can’t be empty. Send content, metadata or both.
object
Replaces the comment’s metadata wholesale (not merged).
string
The user this edit acts as. Required when the comment has an author: pass the author, and the request runs exactly as their own (400 comment/missing-user-id without it). Anyone else gets what their own token gets: 403, or 404 comment/not-found when the author of the comment’s entity has blocked them. Omit it only for an app-owned comment.
Returns — Promise<Comment>

deleteComment

Deletes a comment as its author. The comment stays in its thread as a placeholder.
string
required
The Sublay comment ID to delete.
string
The user this delete acts as. Required when the comment has an author: pass the author, and the request runs exactly as their own (400 comment/missing-user-id without it). Anyone else gets what their own token gets: 403, or 404 comment/not-found when the author of the comment’s entity has blocked them. Omit it only for an app-owned comment.
Returns — Promise<void>

fetchManyComments

Fetches one level of a comment thread, cursor-paginated: an entity’s top-level comments (entityId) or a comment’s direct replies (parentCommentId). Exactly one of the two is required; the props type refuses neither and both. Optionally nests a few levels of replies inside each returned comment. See Fetch Many Comments for the full contract — placeholders, block flags and the request size limit.
For a user’s comments across entities, use users.fetchCommentsByUserId.
Without actingUserId the read is anonymous: isAuthorBlocked and isUnavailable are always false, userReaction is null, no block rule applies, and moderator-removed comments come back as placeholders. With actingUserId you get exactly that user’s view: their block flags and rules, their userReaction, and their own removed comments in full.
string
Fetch this entity’s top-level comments. Pass this or parentCommentId, not both.
string
Fetch this comment’s direct replies. Pass it without entityId: the parent decides the entity.
number
How many comments at the level being fetched. Server default 10, max 100.
string | null
pagination.nextCursor from the previous response, passed as returned. Omit it, or pass null, for the first page. Send the same sortBy, sortDir and sortByReaction as the request that returned it.
"createdAt" | "top" | "controversial"
Sort for the level being fetched. "top" ranks by the raw count of sortByReaction. Server default "createdAt".
"asc" | "desc"
Applies to "createdAt" and "top"; not accepted with "controversial", which ranks one way only. Server default "desc".
ReactionType
With sortBy: "top" only: the reaction to rank by. Server default "upvote".
number
Levels of replies to nest under each returned comment (0–5). Server default 0.
number
Replies per comment in the nested levels (at least 1). Server default 3.
"createdAt" | "top" | "controversial"
Sort for the nested levels. Defaults to sortBy.
"asc" | "desc"
Sort direction for the nested levels. Defaults to sortDir. Not sent when the nested sort is "controversial".
ReactionType
The reaction the nested levels rank by, when their sort is "top".
string
The user to list as: you get exactly what their own access token would get (blocks, their own removed comments in full, moderation details only where they may see them). Omit it for the anonymous view, with no moderation details.
"user" | "grants" | "files" | ("user" | "grants" | "files")[]
Related data to populate, at every level. "files" adds the comment’s images and files (requires the files-images bundle).
Returns — Promise<CursorPaginatedResponse<Comment>> — { data, pagination: { nextCursor, hasMore } }. With replyDepth above 0, each comment carries nested replies in the same shape.

addReaction

Adds a reaction from a user to a comment.
string
required
The Sublay comment ID.
string
required
The user the service key acts as: the reacting user.
ReactionType
required
One of: "upvote", "downvote", "like", "love", "wow", "sad", "angry", "funny".
Returns — Promise<Comment> — the updated comment, as the reacting user sees it: userReaction and reactionCounts reflect the new reaction.

removeReaction

Removes a user’s existing reaction from a comment. It sends DELETE /comments/:commentId/reactions with actingUserId in the query and no body.
string
required
The Sublay comment ID.
string
required
The user the service key acts as, whose reaction to remove.
Returns — Promise<Comment> — the updated comment, as that user sees it. When the user has no reaction on the comment, the comment comes back unchanged.

fetchReactions

Fetches a paginated list of reactions on a comment, optionally filtered by reaction type.
string
required
The Sublay comment ID.
string
The user to list as, with their block filtering, exactly as their own access token. Omit it for the anonymous view.
ReactionType
Filter to a specific reaction type.
number
Page number (1-indexed). Defaults to 1.
number
Results per page: a whole number from 1 to 100. Defaults to 20. A larger value is rejected with 400 comment/invalid-query, never lowered to 100.
string
Sort direction: "asc" or "desc".
Returns — Promise<PaginatedResponse<Reaction>>

getUserReaction

Checks what reaction (if any) a specific user has left on a comment.
string
required
The Sublay comment ID.
string
required
The user the service key acts as, whose reaction is checked.
Returns — Promise<{ reactionType: ReactionType | null }>. Rejects with 404 comment/not-found when the comment doesn’t exist, or is on an entity whose author has blocked the user (the user’s own comments excepted).