Skip to main content
Adds a comment to a post and creates a notification for the post owner.

Endpoint

POST /api/posts/{id}/comment

Authentication

Required. User must be authenticated to comment on a post.

Path Parameters

id
integer
required
The unique identifier of the post to comment on (PostID)

Request Body

userName
string
required
The username of the authenticated user making the comment
commentText
string
required
The text content of the comment. Maximum length: 1000 characters

Behavior

  • Creates a new Comment record
  • Sets initial LikeCount to 0
  • Creates a notification for the post owner
  • Prevents commenting on posts from blocked accounts

Request

curl -X POST https://api.example.com/api/posts/12345/comment \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "userName": "johndoe",
    "commentText": "Great post!"
  }'

Response

status
integer
201 Created - Comment added successfully
Returns a Comment object:
commentID
integer
Unique identifier for the comment
PostID
integer
ID of the post being commented on
CommenterID
integer
ID of the user who made the comment
CommentText
string
The text content of the comment
CreatedAt
datetime
Timestamp when the comment was created
LikeCount
integer
Number of likes on the comment (initially 0)
201 Created

Errors

404
error
Post or account does not exist, or action cannot be completed due to a block
{
  "error": "This post does not exist"
}

Build docs developers (and LLMs) love