Introduction
The Comments API allows you to manage user comments on blog posts, including creating comments, retrieving comments with nested replies, handling likes, and generating statistics about comment activity.All comment endpoints support both approved and pending statuses. Comments start in
pending status by default and require moderation before becoming visible.Get All Comments
Retrieve all comments across the platform with optional filters.Endpoint
Query Parameters
Include full user information in the response
Include nested replies in the response
Page number for pagination
Number of comments per page
Response
Array of comment objects
Unique comment identifier
Comment content text
ID of the post this comment belongs to
ID of the user who created the comment
Comment status:
pending, approved, spam, or rejectedID of parent comment (for nested replies)
Number of likes the comment has received
Whether the comment has been edited
ISO 8601 timestamp of last edit
Nesting depth level (0 for top-level comments)
Hierarchical path for nested comment tracking
Nested array of reply comments (when
withReplies=true)ISO 8601 timestamp of creation
ISO 8601 timestamp of last update
Total number of comments
Current page number
Total number of pages
Example Request
Get Comments by Post
Retrieve all comments for a specific blog post with pagination and filtering options.Endpoint
Function Signature
Parameters
ID of the post to retrieve comments for
Include full user information
Include nested replies
Page number
Comments per page
Example Request
Create Comment
Create a new comment or reply on a blog post.Endpoint
Function Signature
Request Body
The comment content text
ID of the post to comment on
ID of the user creating the comment
ID of parent comment (for nested replies). Omit for top-level comments.
Response
Returns the created comment object with all fields populated, including:- Auto-generated
id statusset topendinglikesinitialized to 0created_atandupdated_attimestamps
Example Request
Get Comment Replies
Retrieve all replies to a specific comment.Endpoint
Function Signature
Parameters
ID of the parent comment
Response
Returns an array of comment objects that are direct replies to the specified comment.The response includes only direct replies (depth + 1). To get the full nested thread, use the
withReplies=true parameter on the main comments endpoint.Example Request
Like Comment
Add a like to a comment.Endpoint
Function Signature
Parameters
ID of the comment to like
Response
Returnstrue if the like was successfully added, false otherwise.
Example Request
Delete Comment
Permanently delete a comment.Endpoint
Function Signature
Parameters
ID of the comment to delete
Response
Returnstrue if deletion was successful, false otherwise.
Example Request
Comments Statistics
Get comprehensive statistics about comments across the platform.Endpoint
Function Signature
Response
Total number of comments
Number of approved comments
Number of comments awaiting moderation
Number of comments marked as spam
Example Request
Top Commented Posts
Get a list of posts with the most comments.Endpoint
Function Signature
Query Parameters
Maximum number of posts to return
Response
Returns an array of posts ordered by comment count (descending).Example Request
Most Active Commenters
Get a list of users who have posted the most comments.Endpoint
Function Signature
Query Parameters
Maximum number of users to return
Response
Returns an array of users ordered by comment count (descending).Example Request
Helper Functions
Get Pending Comments
Filter comments by pending status (local/client-side operation).status === 'pending'.
Get Comments by Post (Local)
Filter comments by post ID (local/client-side operation).Nested Replies Structure
Comments support unlimited nesting depth with the following structure:The API uses
parent_id, depth, and path fields to maintain the comment hierarchy:- parent_id: References the immediate parent comment (null for top-level)
- depth: Integer representing nesting level (0 = top-level)
- path: Hierarchical string path for efficient tree queries
- replies: Array of nested comment objects (when
withReplies=true)
Example Nested Structure
Data Transformation
The API automatically transforms between backend (snake_case) and frontend (camelCase) formats: Backend Format → Frontend Formatcontenido→contentpost_id→postIdusuario_id→authorIdparent_id→parentIdis_edited→isEditededited_at→editedAtcreated_at→createdAtupdated_at→updatedAt
All transformations are handled automatically by
transformCommentFromBackend() and transformCommentToBackend() functions in commentsService.ts:16-69.