1HOUSE API Documentation

Community

Social features, posts, and community engagement

Manage community posts, reactions, and social interactions.

Community Features

Build engaged communities with posts, reactions, comments, trending algorithms, and real-time social interactions.

Overview

The Community API provides:

  • Post management (create, read, update, delete)
  • Reaction system (like, love, celebrate, etc.)
  • Trending posts algorithm
  • Community subscriptions
  • User engagement tracking

Base Paths:

  • Posts: /v1/posts
  • Communities: /v1/communities

Posts

Get All Posts

GET /v1/posts
ParameterTypeDescription
pagenumberPage number
limitnumberResults per page
communityIdstringFilter by community
sortstringrecent, trending, popular
{
  "success": true,
  "status": 200,
  "data": [
    {
      "id": "post_123",
      "userId": "user_456",
      "author": {
        "id": "user_456",
        "firstName": "John",
        "lastName": "Doe",
        "avatar": "https://..."
      },
      "communityId": "community_789",
      "content": "Just closed a profitable EUR/USD trade! Here's my analysis...",
      "images": [
        "https://cdn.yourdomain.com/posts/post_123/img1.jpg"
      ],
      "reactions": {
        "like": 45,
        "love": 12,
        "celebrate": 8
      },
      "commentCount": 23,
      "viewCount": 456,
      "trending": true,
      "createdAt": "2025-10-21T10:00:00.000Z",
      "updatedAt": "2025-10-21T10:00:00.000Z"
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 10,
    "total": 234,
    "pages": 24
  }
}
GET /v1/posts/trending
ParameterTypeDescription
communityIdstringFilter by community
limitnumberNumber of results (default: 10)

Response: Same format as Get All Posts

Get User's Posts

GET /v1/posts/user/:userId

Get Post by ID

GET /v1/posts/:postId
{
  "success": true,
  "status": 200,
  "data": {
    "id": "post_123",
    "content": "...",
    "author": {...},
    "reactions": {...},
    "comments": [
      {
        "id": "comment_1",
        "userId": "user_789",
        "author": {
          "firstName": "Jane",
          "lastName": "Smith"
        },
        "content": "Great analysis!",
        "createdAt": "2025-10-21T10:05:00.000Z"
      }
    ],
    "userReaction": "like"  // Current user's reaction
  }
}

Create Post

POST /v1/posts
{
  "communityId": "community_789",
  "content": "Just closed a profitable EUR/USD trade! 📈",
  "images": [
    "https://cdn.yourdomain.com/temp/upload_123.jpg"
  ],
  "tags": ["trading", "forex", "EUR/USD"]
}

Update Post

PUT /v1/posts/:postId
{
  "content": "Updated content here...",
  "tags": ["trading", "forex"]
}

Note: Only the post author can update their posts

Delete Post

DELETE /v1/posts/:postId

Note: Only the post author or admins can delete posts

Reactions

Add Reaction

POST /v1/posts/:postId/reactions
{
  "type": "like"
}

Reaction Types:

  • like - 👍
  • love - ❤️
  • celebrate - 🎉
  • insightful - 💡
  • support - 🙌
{
  "success": true,
  "status": 200,
  "data": {
    "postId": "post_123",
    "reactions": {
      "like": 46,
      "love": 12,
      "celebrate": 8
    },
    "userReaction": "like"
  }
}

Remove Reaction

DELETE /v1/posts/:postId/reactions
{
  "success": true,
  "status": 200,
  "data": {
    "postId": "post_123",
    "reactions": {
      "like": 45,
      "love": 12,
      "celebrate": 8
    },
    "userReaction": null
  }
}

Communities

Get All Communities

GET /v1/communities
{
  "success": true,
  "status": 200,
  "data": [
    {
      "id": "community_789",
      "name": "Forex Traders",
      "description": "Community for forex trading discussion",
      "icon": "💹",
      "memberCount": 5432,
      "postCount": 1234,
      "isSubscribed": true,
      "createdAt": "2024-01-01T00:00:00.000Z"
    }
  ]
}

Get Community Details

GET /v1/communities/:communityId

Subscribe to Community

POST /v1/communities/:communityId/subscribe

Unsubscribe from Community

DELETE /v1/communities/:communityId/subscribe

Posts are ranked by:

  1. Recency - Recent posts ranked higher
  2. Reactions - More reactions = higher rank
  3. Comments - Active discussions rank higher
  4. View Velocity - Rapidly viewed posts rank higher

Formula:

trending_score = (reactions * 2 + comments * 3 + views) / age_in_hours

Code Examples

React Component

function CommunityFeed() {
  const [posts, setPosts] = useState([]);
  
  useEffect(() => {
    fetchPosts();
  }, []);

  const fetchPosts = async () => {
    const response = await fetch('/v1/posts?sort=trending', {
      headers: {
        'X-API-Key': apiKey,
        'Authorization': `Bearer ${token}`
      }
    });

    const { data } = await response.json();
    setPosts(data);
  };

  const addReaction = async (postId, type) => {
    await fetch(`/v1/posts/${postId}/reactions`, {
      method: 'POST',
      headers: {
        'X-API-Key': apiKey,
        'Authorization': `Bearer ${token}`,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({ type })
    });

    fetchPosts();  // Refresh
  };

  return (
    <div>
      {posts.map(post => (
        <div key={post.id}>
          <p>{post.content}</p>
          <button onClick={() => addReaction(post.id, 'like')}>
            👍 {post.reactions.like}
          </button>
        </div>
      ))}
    </div>
  );
}