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.The comment text content.
null or an empty string stores none — a comment needs content, a gif, attachments, images or files.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.).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.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.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.
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).Promise<Comment>
fetchCommentByForeignId
Fetches a comment by your application’s own identifier.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.
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).Promise<Comment>
updateComment
Updates the content or metadata of an existing comment, as its author.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.Promise<Comment>
deleteComment
Deletes a comment as its author. The comment stays in its thread as a placeholder.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.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.
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.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.Sort for the level being fetched.
"top" ranks by the raw count of sortByReaction. Server default "createdAt".Applies to
"createdAt" and "top"; not accepted with "controversial", which ranks one way only. Server default "desc".Sort direction for the nested levels. Defaults to
sortDir. Not sent when the nested sort is "controversial".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.
Related data to populate, at every level.
"files" adds the comment’s images and files (requires the files-images bundle).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.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 sendsDELETE /comments/:commentId/reactions with actingUserId in the query and no body.
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.The user to list as, with their block filtering, exactly as their own access token. Omit it for the anonymous view.
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.Promise<PaginatedResponse<Reaction>>
getUserReaction
Checks what reaction (if any) a specific user has left on a comment.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).
