JackaL
友一人
- Joined
- Sep 3, 2026
- Messages
- 341
- Reaction score
- 61
[DEV] Creating Custom XenForo 2.3 API Endpoints
If you want to build a React Native mobile app for your forum, the default XenForo API might lack specific data. Here is how to create a custom REST API endpoint in XenForo to fetch custom user fields.
The PHP Implementation:
Create a new PHP class inside your custom Add-on directory (
If you want to build a React Native mobile app for your forum, the default XenForo API might lack specific data. Here is how to create a custom REST API endpoint in XenForo to fetch custom user fields.
The PHP Implementation:
Create a new PHP class inside your custom Add-on directory (
src/addons/YourAddon/Api/Controller/CustomUser.php).
PHP:
<?php
namespace YourAddon\Api\Controller;
use XF\Api\Controller\AbstractController;
class CustomUser extends AbstractController
{
public function actionGet()
{
$userId = $this->filter('user_id', 'uint');
$user = $this->assertRecordExists('XF:User', $userId);
// Fetch custom field (e.g., our postbit_bg)
$customFields = $user->Profile->custom_fields;
return $this->apiResult([
'user' => $user->toApiResult(),
'postbit_background' => $customFields->postbit_bg
]);
}
}
Ensure you register the API route prefix in the XenForo Admin Control Panel (Development -> API Routes) pointing to this controller class.