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
| Parameter | Type | Required | Description |
|---|---|---|---|
| contentId | GUID | Yes | Post or story ID |
| contentType | string | Yes | Post or Story |
| userId | GUID | Yes | Current user ID |
| parentCommentId | string | Reply only | Parent comment ID for replies |
Request Body (form)
| Field | Type | Required | Description |
|---|---|---|---|
| Text | string | No* | Comment text (*required if no MediaFile) |
| MediaFile | file | No | Optional image/file |
| CommentType | string | No | Comment type |
| Mentions | string | No | JSON 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.