Skip to main content

Overview

The Interactions API handles user engagement with posts including likes, view tracking, and content organization through keywords and categories.

View Tracking

Increment View Count

Track a post view with optional user and IP tracking.
export async function incrementarVista(
  postId: number,
  userId?: number,
  ipAddress?: string
): Promise<boolean>

Parameters

postId
number
required
ID of the post being viewed
userId
number
ID of the viewing user (optional, for logged-in users)
ipAddress
string
IP address of the viewer (used for duplicate detection)

Response

Returns true if view was counted, false if it failed.
The backend implements duplicate detection to prevent inflated view counts from the same user/IP within a time window.

Like Management

Add Like

Add a like to a post from a specific user.
export async function darLike(postId: number, userId: number): Promise<boolean>

Parameters

postId
number
required
ID of the post to like
userId
number
required
ID of the user liking the post

Response

Returns true if like was added successfully.
Users can only like a post once. Subsequent calls with the same userId will return success but won’t increment the counter.

Remove Like

Remove a like from a post.
export async function quitarLike(postId: number, userId: number): Promise<boolean>

Parameters

postId
number
required
ID of the post to unlike
userId
number
required
ID of the user removing their like

Response

Returns true if like was removed successfully.

Keyword Management

Keywords are tags that help organize and discover content. They can be managed independently or attached to posts.

Get Post Keywords

Retrieve all keywords associated with a post.
export async function getPostKeywords(postId: number): Promise<any[]>

Parameters

postId
number
required
ID of the post

Response

[
  {
    "id": 5,
    "keyword": "marketing",
    "usage_count": 42
  },
  {
    "id": 12,
    "keyword": "seo",
    "usage_count": 38
  }
]

Add Existing Keywords

Attach existing keywords to a post by their IDs.
export async function addKeywordsToPost(
  postId: number,
  keywordIds: number[]
): Promise<boolean>

Parameters

postId
number
required
ID of the post
keywordIds
number[]
required
Array of keyword IDs to attach

Create and Add New Keywords

Create new keywords and attach them to a post in one operation.
export async function createAndAddKeywords(
  postId: number,
  keywords: string[]
): Promise<boolean>

Parameters

postId
number
required
ID of the post
keywords
string[]
required
Array of keyword strings to create and attach
If a keyword already exists in the system, it will be reused instead of creating a duplicate.

Remove Keywords

Remove keywords from a post.
export async function removeKeywordsFromPost(
  postId: number,
  keywordIds?: number[]
): Promise<boolean>

Parameters

postId
number
required
ID of the post
keywordIds
number[]
Array of keyword IDs to remove. If omitted, removes all keywords.

Find or Create Keyword

Find an existing keyword by name or create it if it doesn’t exist.
export async function findOrCreateKeyword(keyword: string): Promise<any>

Parameters

keyword
string
required
Keyword string to find or create

Response

{
  "id": 25,
  "keyword": "blockchain",
  "usage_count": 1,
  "created": true
}

Get Most Used Keywords

Retrieve the most frequently used keywords across all posts.
export async function getKeywordsMasUsadas(limit: number = 50): Promise<any[]>

Parameters

limit
number
default:"50"
Number of keywords to return (max 200)

Response

[
  {
    "id": 5,
    "keyword": "marketing",
    "usage_count": 127
  },
  {
    "id": 8,
    "keyword": "seo",
    "usage_count": 94
  }
]

Category Management

Add Categories to Post

Attach one or more categories to a post.
export async function addCategoriasToPost(
  postId: number,
  categoriaIds: number[]
): Promise<boolean>

Parameters

postId
number
required
ID of the post
categoria_ids
number[]
required
Array of category IDs to attach
Posts can have multiple categories. For the primary category, use the categoryId field when creating/updating the post.

Complete Example: Interactive Post

Here’s a complete example showing how to build an interactive post experience:
class PostInteractionManager {
  private postId: number;
  private userId: number;
  private userLiked: boolean = false;

  constructor(postId: number, userId: number) {
    this.postId = postId;
    this.userId = userId;
  }

  // Initialize when post loads
  async initialize() {
    // Track the view
    await incrementarVista(this.postId, this.userId);
    
    // Load post data including current like state
    const post = await getPostById(this.postId);
    return post;
  }

  // Toggle like state
  async toggleLike() {
    if (this.userLiked) {
      const success = await quitarLike(this.postId, this.userId);
      if (success) {
        this.userLiked = false;
        return { liked: false, action: 'removed' };
      }
    } else {
      const success = await darLike(this.postId, this.userId);
      if (success) {
        this.userLiked = true;
        return { liked: true, action: 'added' };
      }
    }
    return null;
  }

  // Manage tags
  async updateTags(tags: string[]) {
    // Remove old keywords
    await removeKeywordsFromPost(this.postId);
    
    // Add new keywords
    await createAndAddKeywords(this.postId, tags);
    
    return await getPostKeywords(this.postId);
  }

  // Get related content by keywords
  async getRelatedPosts() {
    const keywords = await getPostKeywords(this.postId);
    // Use keywords to find similar posts
    // Implementation depends on your search/filter logic
  }
}

// Usage
const postManager = new PostInteractionManager(123, currentUser.id);
await postManager.initialize();

// User clicks like button
const likeResult = await postManager.toggleLike();
if (likeResult?.action === 'added') {
  showNotification('Post liked!');
}

// Update tags
await postManager.updateTags(['react', 'typescript', 'web-development']);

Best Practices

  • Always track views on the client-side when post loads
  • Include userId for logged-in users to prevent duplicate counting
  • Include ipAddress for anonymous users to reduce bot inflation
  • Don’t track views for preview/draft modes
  • Check like state on page load to show correct UI
  • Implement optimistic UI updates for better UX
  • Handle errors gracefully (network failures)
  • Consider debouncing rapid like/unlike actions
  • Use 3-7 keywords per post for optimal discoverability
  • Choose specific keywords over broad ones (“react-hooks” vs “javascript”)
  • Review most-used keywords monthly to identify trending topics
  • Implement keyword autocomplete using getKeywordsMasUsadas()
  • Assign 1-3 categories per post
  • Use categoryId for the primary category
  • Use addCategoriasToPost() for additional categories
  • Keep category structure shallow (2-3 levels max)

Build docs developers (and LLMs) love