Skip to main content

Create Reply

Authentication

This endpoint requires user authentication.
Authorization: Bearer <user_token>

Path Parameters

postId
string
required
The unique identifier of the post to reply to

Request Body

content
string
required
Reply content (1-3000 characters, will be trimmed)

Response

success
boolean
Indicates whether the reply was created successfully
reply
object
The newly created reply object
message
string
Error message if success is false

Code Examples

const postId = '64a1b2c3d4e5f6789abcdef0';

const response = await fetch(
  `https://api.skillrise.com/api/community/posts/${postId}/replies`,
  {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer YOUR_TOKEN'
    },
    body: JSON.stringify({
      content: 'Great question! Here are some tips for optimizing React renders...'
    })
  }
);

const data = await response.json();
console.log(data.reply);

Response Example

Success
{
  "success": true,
  "reply": {
    "_id": "64a1b2c3d4e5f6789abcdef5",
    "postId": "64a1b2c3d4e5f6789abcdef0",
    "content": "Great question! Here are some tips for optimizing React renders...",
    "authorName": "John Smith",
    "authorImage": "https://example.com/john-avatar.jpg",
    "isAuthor": true,
    "upvoteCount": 0,
    "isUpvoted": false,
    "isAcceptedAnswer": false,
    "createdAt": "2024-03-15T14:25:00.000Z"
  }
}
Post Not Found
{
  "success": false,
  "message": "Post not found"
}
Missing Content
{
  "success": false,
  "message": "Reply content is required"
}

Toggle Reply Upvote

Authentication

This endpoint requires user authentication.
Authorization: Bearer <user_token>

Path Parameters

postId
string
required
The unique identifier of the post
replyId
string
required
The unique identifier of the reply

Response

success
boolean
Indicates whether the operation was successful
upvoteCount
number
Updated upvote count
isUpvoted
boolean
New upvote status (true if upvoted, false if removed)
message
string
Error message if success is false

Code Examples

const postId = '64a1b2c3d4e5f6789abcdef0';
const replyId = '64a1b2c3d4e5f6789abcdef5';

const response = await fetch(
  `https://api.skillrise.com/api/community/posts/${postId}/replies/${replyId}/upvote`,
  {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_TOKEN'
    }
  }
);

const data = await response.json();
console.log(`Upvotes: ${data.upvoteCount}, Upvoted: ${data.isUpvoted}`);

Response Example

Upvoted
{
  "success": true,
  "upvoteCount": 5,
  "isUpvoted": true
}
Removed Upvote
{
  "success": true,
  "upvoteCount": 4,
  "isUpvoted": false
}
Reply Not Found
{
  "success": false,
  "message": "Reply not found"
}

Accept Answer

Authentication

This endpoint requires user authentication. Only the post author can accept answers.
Authorization: Bearer <user_token>

Path Parameters

postId
string
required
The unique identifier of the post
replyId
string
required
The unique identifier of the reply to accept

Response

success
boolean
Indicates whether the operation was successful
isAcceptedAnswer
boolean
New acceptance status (true if accepted)
postResolved
boolean
Whether the post is now marked as resolved
message
string
Error message if success is false

Code Examples

const postId = '64a1b2c3d4e5f6789abcdef0';
const replyId = '64a1b2c3d4e5f6789abcdef5';

const response = await fetch(
  `https://api.skillrise.com/api/community/posts/${postId}/replies/${replyId}/accept`,
  {
    method: 'PATCH',
    headers: {
      'Authorization': 'Bearer YOUR_TOKEN'
    }
  }
);

const data = await response.json();
console.log('Answer accepted:', data.isAcceptedAnswer);

Response Example

Answer Accepted
{
  "success": true,
  "isAcceptedAnswer": true,
  "postResolved": true
}
Not Post Author
{
  "success": false,
  "message": "Only the post author can accept an answer"
}
Reply Not Found
{
  "success": false,
  "message": "Reply not found"
}

Behavior Notes

Reply Creation

  • Reply content is limited to 3000 characters and will be trimmed
  • Creating a reply increments the post’s replyCount
  • The reply author’s name and image are automatically fetched from the user profile

Upvoting Replies

  • Upvoting is a toggle action - calling the endpoint again removes the upvote
  • Users can upvote their own replies
  • The response includes the updated upvote count and the user’s new upvote status

Accepting Answers

  • Only the post author can accept answers
  • Only one reply can be accepted at a time per post
  • Accepting a reply automatically marks the post as resolved
  • Calling the endpoint on an already-accepted reply unaccepts it (toggles)
  • When a reply is accepted, all other replies on that post are automatically unaccepted
  • Accepted answers appear first when retrieving replies (sorted by isAcceptedAnswer: true first)

Reply Sorting

When fetching a post with replies (via GET /api/community/posts/:postId):
  1. Accepted answer appears first (if any)
  2. Other replies sorted by creation date (oldest first)

Permissions

ActionRequirement
Create ReplyAuthenticated user
Upvote ReplyAuthenticated user
Accept AnswerPost author only

Error Responses

All endpoints return consistent error formats:
Authentication Required
{
  "success": false,
  "message": "Authentication required"
}
Not Authorized
{
  "success": false,
  "message": "Not authorized"
}
Server Error
{
  "success": false,
  "message": "An unexpected error occurred"
}