Skip to main content

Get Posts

Authentication

Authentication is optional. If authenticated, the response includes upvote status and author flags.

Query Parameters

groupId
string
Filter posts by specific group ID
tab
string
Filter posts by tab:
  • "all" (default) - All posts
  • "trending" - Posts sorted by upvotes
  • "myGroups" - Posts from groups the user is a member of (requires authentication)
page
number
Page number for pagination (default: 1, 15 posts per page)

Response

success
boolean
Indicates whether the request was successful
posts
array
Array of post objects
hasMore
boolean
Whether there are more posts available
total
number
Total number of posts matching the query

Code Example

// Get trending posts
const response = await fetch(
  'https://api.skillrise.com/api/community/posts?tab=trending&page=1',
  {
    headers: {
      'Authorization': 'Bearer YOUR_TOKEN' // Optional
    }
  }
);

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

Response Example

{
  "success": true,
  "posts": [
    {
      "_id": "64a1b2c3d4e5f6789abcdef0",
      "title": "How to optimize React renders?",
      "content": "I'm working on a large React application and noticing performance issues...",
      "authorName": "Jane Doe",
      "authorImage": "https://example.com/avatar.jpg",
      "isAuthor": false,
      "group": {
        "_id": "64a1b2c3d4e5f6789abcdef1",
        "name": "React Enthusiasts",
        "slug": "react-enthusiasts",
        "icon": "⚛️"
      },
      "tags": ["react", "performance", "optimization"],
      "upvoteCount": 24,
      "isUpvoted": true,
      "replyCount": 8,
      "isResolved": false,
      "createdAt": "2024-03-15T10:30:00.000Z"
    }
  ],
  "hasMore": true,
  "total": 156
}

Create Post

Authentication

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

Request Body

title
string
required
Post title (1-200 characters, will be trimmed)
content
string
required
Post content (1-5000 characters, will be trimmed)
groupId
string
Group ID to post in (optional, null for general posts)
tags
array
Array of tag strings or comma-separated string (max 5 tags)

Response

success
boolean
Indicates whether the post was created successfully
post
object
The newly created post object (same structure as Get Posts response)
message
string
Error message if success is false

Code Example

const response = await fetch('https://api.skillrise.com/api/community/posts', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer YOUR_TOKEN'
  },
  body: JSON.stringify({
    title: 'Best practices for async/await in JavaScript',
    content: 'I\'ve been learning about async/await and wanted to share some patterns I\'ve found helpful...',
    groupId: '64a1b2c3d4e5f6789abcdef1',
    tags: ['javascript', 'async', 'best-practices']
  })
});

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

Get Single Post

Path Parameters

postId
string
required
The unique identifier of the post

Response

Includes the full post object with a replies array containing all replies. Accepted answers appear first, followed by other replies sorted by creation date.
post
object

Toggle Post Upvote

Authentication

This endpoint requires user authentication.

Path Parameters

postId
string
required
The unique identifier of the post

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)

Code Example

const postId = '64a1b2c3d4e5f6789abcdef0';

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

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

Toggle Post Resolved

Authentication

This endpoint requires user authentication. Only the post author can resolve/unresolve.

Path Parameters

postId
string
required
The unique identifier of the post

Response

success
boolean
Indicates whether the operation was successful
isResolved
boolean
New resolved status

Code Example

const postId = '64a1b2c3d4e5f6789abcdef0';

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

const data = await response.json();

Delete Post

Authentication

This endpoint requires user authentication. Only the post author can delete their post.

Path Parameters

postId
string
required
The unique identifier of the post

Response

success
boolean
Indicates whether the post was deleted successfully

Code Example

const postId = '64a1b2c3d4e5f6789abcdef0';

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

const data = await response.json();

Notes

  • Posts can belong to a specific group or be general (no group)
  • Tags can be provided as an array or comma-separated string
  • The “trending” tab sorts posts by upvote count (descending), then by creation date
  • The “myGroups” tab filters posts from groups the user has joined
  • Pagination returns 15 posts per page
  • Deleting a post also deletes all associated replies
  • Only post authors can resolve/unresolve or delete their posts
  • Upvoting is a toggle action - calling it again removes the upvote