Create Comment
Endpoint
URL: /:projectId/comments
Method: POST
Authentication Required: Yes
Description
Creates a new comment or reply on a specific entity.
- Comments can include text, a GIF, mentions, attachments, and metadata.
- Only authenticated users (or master clients) may create comments.
- Automatically handles reputation and notification logic.
Request
Headers
Header | Type | Required | Description |
---|---|---|---|
Authorization | string | Yes | Bearer token for authenticated users. |
Body Parameters
Field | Type | Required | Description |
---|---|---|---|
entityId | string | Yes | ID of the entity to attach the comment to. |
content | string | No* | Text content of the comment. Required unless gif is provided. |
gif | IGif | No* | GIF object. Required unless content is provided. |
mentions | IMention[] | No | List of mentioned users. |
parentId | string | No | ID of the parent comment (for replies). |
referencedCommentId | string | No | ID of a referenced (quoted) comment. |
foreignId | string | No | Optional external reference ID. |
attachments | Record<string, any>[] | No | List of attached files or resources. |
metadata | Record<string, any> | No | Custom metadata for this comment. |
userId | string | No | Allowed only for master clients. Posts the comment on behalf of a user. |
Example Request
{
"entityId": "a1b2c3d4",
"content": "Great article!",
"mentions": [{ "id": "user-123", "username": "alex" }],
"gif": null,
"parentId": "comment-456",
"attachments": [],
"metadata": { "source": "web" }
}
Response
Success Response (201 Created
)
Returns the newly created comment object:
{
"id": "comment-789",
"entityId": "a1b2c3d4",
"userId": "user-456",
"content": "Great article!",
"mentions": [{ "id": "user-123", "username": "alex" }],
"gif": null,
"attachments": [],
"metadata": { "source": "web" },
"createdAt": "2025-05-11T10:00:00.000Z",
"updatedAt": "2025-05-11T10:00:00.000Z"
}
Error Responses
Missing Entity ID (400 Bad Request
)
{
"error": "Missing entity ID",
"code": "comment/missing-entity-id"
}
Missing Content (400 Bad Request
)
{
"error": "Missing required comment content",
"code": "comment/missing-content"
}
Missing User ID (400 Bad Request
)
{
"error": "Missing user ID",
"code": "comment/missing-user-id"
}
Entity Not Found (404 Not Found
)
{
"error": "Entity not found",
"code": "comment/entity-not-found"
}
Server Error (500 Internal Server Error
)
{
"error": "Internal server error",
"code": "comment/server-error",
"details": "[error message]"
}
Notes
-
Either
content
orgif
must be present. -
If
userId
is provided, the request must come from a master client. -
Reputation is awarded to the user who posts the comment.
-
Notifications are triggered automatically:
- To the entity author
- To the parent comment author (for replies)
- To each mentioned user (excluding duplicates)
-
API usage for comments is tracked via Redis.
Gif Structure
interface IGif {
altText: string;
gifPreviewUrl: string;
gifUrl: string;
id: string;
url: string;
aspectRatio: string;
}
Mention Structure
interface IMention {
id: string; // User ID
username: string; // Username at time of mention
}