una icon indicating copy to clipboard operation
una copied to clipboard

API endpoints do not return post labels field

Open eaguirrek12com opened this issue 2 months ago • 0 comments

The UNA CMS REST API endpoints for posts do not return the labels field, even though labels are stored in the database and are accessible through the web interface.

Affected Endpoints

  1. system/get_info/TemplServiceContent - Does not return labels field
  2. bx_posts/browse/Module - Does not return labels field
  3. All other browse endpoints for posts

Current Behavior

When retrieving post data via API:

Request:

GET /api.php?r=system/get_info/TemplServiceContent&params=["bx_posts",40]

Response:

{
  "id": 40,
  "module": "bx_posts",
  "title": "Post Title",
  "author": {...},
  "url": "...",
  "image": "...",
  "summary_plain": "..."
  // labels field is missing
}

Database:

SELECT labels FROM bx_posts_posts WHERE id = 40;
-- Result: a:1:{i:0;s:9:"My School";}

The labels field exists in the database but is filtered out by the API response.

Expected Behavior

The API should return the labels field in the response, similar to other post fields:

{
  "id": 40,
  "module": "bx_posts",
  "title": "Post Title",
  "labels": ["My School"],
  ...
}

Root Cause

For system/get_info/TemplServiceContent:

  • File: public/modules/base/text/classes/BxBaseModTextModule.php
  • Method: decodeDataAPI() (lines 815-854)
  • The method explicitly filters which fields are returned and does not include labels

For browse endpoints:

  • File: public/modules/boonex/posts/classes/BxPostsSearchResult.php
  • Property: ownFields array (line 24)
  • The array defines: array('id', 'title', 'abstract', 'text', 'thumb', 'thumb_data', 'author', 'added')
  • The labels field is not included

Proposed Solution

  1. Add labels to the decodeDataAPI() method in BxBaseModTextModule.php
  2. Add labels to the ownFields array in BxPostsSearchResult.php
  3. Ensure the serialized labels are properly unserialized before being returned in the API response

Use Case

We need to retrieve post labels via API for:

  • Mobile applications that display post metadata
  • Third-party integrations that need to filter/display posts by labels
  • Analytics and reporting tools that categorize posts by labels

Workaround

Currently, the only way to access post labels is through direct database queries, which bypasses UNA's permission system and is not ideal for API consumers.

Environment

  • UNA Version: 14
  • PHP Version: 8.1
  • Affected Modules: Posts (bx_posts), and likely all text-based modules (Events, Polls, etc.)

Additional Notes

This limitation affects all text-based content modules that extend BxBaseModTextModule, not just posts. A fix for the base class would benefit all derived modules.

eaguirrek12com avatar Oct 24 '25 21:10 eaguirrek12com