Skip to main content

Create Comment

Add a comment to a post or story. The backend uses api/Comment. Create is multipart/form-data with query params contentId, contentType (e.g. Post), userId; reply uses api/Comment/reply with parentCommentId in query.

Endpoints

Create comment

POST /api/Comment?contentId={postId}&contentType=Post&userId={userId}
Content-Type: multipart/form-data

Authentication: Required

Reply to comment

POST /api/Comment/reply?contentId={postId}&contentType=Post&userId={userId}&parentCommentId={parentCommentId}
Content-Type: multipart/form-data

Query Parameters

ParameterTypeRequiredDescription
contentIdGUIDYesPost or story ID
contentTypestringYesPost or Story
userIdGUIDYesCurrent user ID
parentCommentIdstringReply onlyParent comment ID for replies

Request Body (form)

FieldTypeRequiredDescription
TextstringNo*Comment text (*required if no MediaFile)
MediaFilefileNoOptional image/file
CommentTypestringNoComment type
MentionsstringNoJSON array of mention objects

Response

Success (201 Created)

{
"success": true,
"data": {
"id": "comment-id",
"content": "Great post!",
"author": {
"id": "user-id",
"fullName": "John Doe",
"username": "johndoe"
},
"postId": "post-id",
"parentCommentId": null,
"reactions": {
"like": 2,
"total": 2
},
"repliesCount": 0,
"createdAt": "2024-01-01T00:00:00Z"
}
}

Example

// Top-level comment (multipart/form-data)
const formData = new FormData();
formData.append('Text', 'Great post!');
const response = await fetch(
`http://localhost:5000/api/Comment?contentId=${postId}&contentType=Post&userId=${userId}`,
{
method: 'POST',
headers: { 'Authorization': `Bearer ${token}` },
body: formData
}
);

// Reply to comment
const replyForm = new FormData();
replyForm.append('Text', 'I agree!');
const replyResponse = await fetch(
`http://localhost:5000/api/Comment/reply?contentId=${postId}&contentType=Post&userId=${userId}&parentCommentId=${parentCommentId}`,
{
method: 'POST',
headers: { 'Authorization': `Bearer ${token}` },
body: replyForm
}
);

Nested Comments

Use POST /api/Comment/reply with parentCommentId to create replies.

Next Steps