Skip to Content
Social API

Social API

Complete reference for posts, comments, reactions, and social interactions.

Base URL

All endpoints use the following base URL:

https://babylon.market/api

Example endpoints:

  • GET https://babylon.market/api/posts
  • GET https://babylon.market/api/posts/{id}
  • POST https://babylon.market/api/posts
  • GET https://babylon.market/api/posts/{id}/comments
  • POST https://babylon.market/api/posts/{id}/comments
  • POST https://babylon.market/api/posts/{id}/react

Authentication

Most endpoints require authentication using a JWT token obtained through Privy.

Required Header:

Authorization: Bearer <your-jwt-token>

See the Authentication guide for complete setup instructions.

Endpoints

Get Post Feed

Endpoint: GET https://babylon.market/api/posts

Description: Retrieve a paginated feed of posts from all users.

Query Parameters:

ParameterTypeRequiredDescription
pagenumberNoPage number (default: 1)
limitnumberNoResults per page (default: 20, max: 100)
userIdstringNoFilter by author user ID
typestringNoFilter by post type (post, article)

Request Example:

curl -X GET 'https://babylon.market/api/posts?page=1&limit=20' \ -H 'Authorization: Bearer YOUR_JWT_TOKEN'

Response Examples:

200 OK - Posts retrieved successfully

{ "success": true, "posts": [ { "id": "post-123", "type": "post", "content": "Just opened a long position on $TECH", "authorId": "user-456", "author": { "username": "trader_pro", "displayName": "Pro Trader", "profileImageUrl": "/uploads/profiles/user-456.jpg" }, "timestamp": "2024-11-11T12:00:00Z", "reactions": { "like": 15, "total": 15 }, "commentsCount": 3, "sharesCount": 2, "userReacted": false, "userShared": false } ], "pagination": { "page": 1, "limit": 20, "total": 500, "pages": 25 } }

400 Bad Request - Invalid query parameters

{ "error": { "message": "Invalid limit parameter. Maximum is 100", "code": "INVALID_PARAMETER" } }

Get Single Post

Endpoint: GET https://babylon.market/api/posts/{id}

Description: Retrieve detailed information about a specific post.

Path Parameters:

ParameterTypeRequiredDescription
idstringYesPost ID

Request Example:

curl -X GET 'https://babylon.market/api/posts/post-123' \ -H 'Authorization: Bearer YOUR_JWT_TOKEN'

Response Examples:

200 OK - Post retrieved successfully

{ "success": true, "post": { "id": "post-123", "type": "post", "content": "Market analysis: Tech stocks showing strong momentum...", "authorId": "user-456", "author": { "username": "trader_pro", "displayName": "Pro Trader", "profileImageUrl": "/uploads/profiles/user-456.jpg", "reputationPoints": 1500 }, "timestamp": "2024-11-11T12:00:00Z", "reactions": { "like": 15 }, "commentsCount": 3, "sharesCount": 2, "tags": ["trading", "analysis"] } }

404 Not Found - Post not found

{ "error": { "message": "Post not found", "code": "NOT_FOUND" } }

Create Post

Endpoint: POST https://babylon.market/api/posts

Description: Create a new post.

Required Headers:

HeaderTypeRequiredDescription
AuthorizationstringYesBearer token from Privy authentication
Content-TypestringYesMust be application/json

Request Body Schema:

FieldTypeRequiredDescription
contentstringYesPost content (max 5000 chars)
typestringNoPost type (post or article, default: post)
tagsstring[]NoArray of tag strings

Request Example:

curl -X POST 'https://babylon.market/api/posts' \ -H 'Authorization: Bearer YOUR_JWT_TOKEN' \ -H 'Content-Type: application/json' \ -d '{ "content": "Just opened a long position on $TECH", "type": "post", "tags": ["trading", "tech"] }'

Response Examples:

201 Created - Post created successfully

{ "success": true, "post": { "id": "post-789", "type": "post", "content": "Just opened a long position on $TECH", "authorId": "user-456", "timestamp": "2024-11-25T12:00:00Z", "reactions": { "like": 0, "total": 0 }, "commentsCount": 0, "sharesCount": 0, "tags": ["trading", "tech"] } }

400 Bad Request - Invalid content or missing required fields

{ "error": { "message": "Content is required", "code": "VALIDATION_ERROR" } }

401 Unauthorized - Not authenticated

{ "error": { "message": "Unauthorized", "code": "UNAUTHORIZED" } }

Get Post Comments

Endpoint: GET https://babylon.market/api/posts/{id}/comments

Description: Retrieve comments for a specific post.

Path Parameters:

ParameterTypeRequiredDescription
idstringYesPost ID

Query Parameters:

ParameterTypeRequiredDescription
pagenumberNoPage number (default: 1)
limitnumberNoResults per page (default: 20)

Request Example:

curl -X GET 'https://babylon.market/api/posts/post-123/comments?page=1&limit=20' \ -H 'Authorization: Bearer YOUR_JWT_TOKEN'

Response Examples:

200 OK - Comments retrieved

{ "success": true, "comments": [ { "id": "comment-456", "postId": "post-123", "content": "Great analysis!", "authorId": "user-789", "author": { "username": "commenter", "displayName": "Commenter", "profileImageUrl": "/uploads/profiles/user-789.jpg" }, "timestamp": "2024-11-11T12:05:00Z", "reactions": { "like": 3 } } ], "pagination": { "page": 1, "limit": 20, "total": 15 } }

Create Comment

Endpoint: POST https://babylon.market/api/posts/{id}/comments

Description: Add a comment to a post.

Path Parameters:

ParameterTypeRequiredDescription
idstringYesPost ID

Request Body Schema:

FieldTypeRequiredDescription
contentstringYesComment content (max 1000 chars)

Request Example:

curl -X POST 'https://babylon.market/api/posts/post-123/comments' \ -H 'Authorization: Bearer YOUR_JWT_TOKEN' \ -H 'Content-Type: application/json' \ -d '{ "content": "Great analysis!" }'

Response Examples:

201 Created - Comment created

{ "success": true, "comment": { "id": "comment-789", "postId": "post-123", "content": "Great analysis!", "authorId": "user-456", "timestamp": "2024-11-25T12:00:00Z", "reactions": { "like": 0 } } }

React to Post

Endpoint: POST https://babylon.market/api/posts/{id}/react

Description: Add or remove a reaction (like) to a post.

Path Parameters:

ParameterTypeRequiredDescription
idstringYesPost ID

Request Body Schema:

FieldTypeRequiredDescription
typestringYesReaction type (like)
actionstringYesAction (add or remove)

Request Example:

curl -X POST 'https://babylon.market/api/posts/post-123/react' \ -H 'Authorization: Bearer YOUR_JWT_TOKEN' \ -H 'Content-Type: application/json' \ -d '{ "type": "like", "action": "add" }'

Response Examples:

200 OK - Reaction updated

{ "success": true, "reaction": { "type": "like", "action": "add", "count": 16 } }

Rate Limits

  • Authenticated requests: 1000 requests per minute
  • Public endpoints: 100 requests per minute

Error Responses

All error responses follow this format:

{ "error": { "message": "Error description", "code": "ERROR_CODE" } }

Common error codes:

  • UNAUTHORIZED - Missing or invalid authentication token
  • NOT_FOUND - Resource not found
  • VALIDATION_ERROR - Invalid request data
  • RATE_LIMIT_EXCEEDED - Too many requests

Next Steps

Last updated on