API endpoint: Find a User by Criteria

API endpoint: Find a User by Criteria 1.0.2

没有下载权限
XF 兼容性
  1. 2.3.x
  2. 2.2.x
摘要
Adds a new endpoint to the Users API controller allowing developers to retrieve a user based
Adds a new endpoint to the Users API controller allowing developers to retrieve a user based on one of three criteria:

  1. user_id
  2. email
  3. username
All parameters are optional and if more than one is specified, the search is performed against each criteria above in the order listed.

For example, if all three parameters are specified and a user_id match is found, that will be returned regardless of the email or username parameters. Similarly, if the user_id is not found, but the email address is, then the user with that email address will be returned regardless of the username specified.



The endpoint can be found at: GET users/find-criteria

This addon was created to help me integrate my forums with my helpdesk system (HelpSpot). When viewing helpdesk requests in HelpSpot, we can perform a "Live lookup" to an external system to retrieve user data to display and/or store in the helpdesk system. In my case, I have it query my forums and return information such as usernames, user status, registration date, and even a link to their user profile on the forums.


1735552738487.webp




Sometimes I have a user_id, sometimes I have an email address and sometimes I have a username - so the system just sends what it has to the XenForo API and then returns the user found. Note that there is an intermediate component that translates the HelpSpot request into a XenForo API call, and then translates the user data return from XenForo into the XML format required by HelpSpot.

Requirements:

You will need an API key with the user:read scope, and if you want to retrieve email address data in the response, the API user will also need Administrator privileges with the Manage users and moderators permission.

Response:

There are two top elements in the response data returned:

  • user - contains the full user record as per the User data type
  • urls - a list of URLs for more information about this user:
    • api - a link to the API call to retrieve information about this user directly based on the user id (from the core API)
    • public - a link to the public XenForo profile for this user
    • admin - a link to the admin XenForo profile for this user

Examples:
cURL
PHP:
<?php
$curl = curl_init();
curl_setopt_array($curl, [
  CURLOPT_URL => "http://xenforo21.local/api/users/find-criteria?user_id=2&[email protected]&username=test%20user",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_TIMEOUT => 0,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => [
    "XF-Api-Key: your-api-key",
  ],
]);
$response = curl_exec($curl);
curl_close($curl);
$data = json_decode($response, true);
var_dump($data);


Guzzle
PHP:
    $client = new \GuzzleHttp\Client([
        'base_uri' => 'http://xenforo21.local/api/'
    ]);
    $response = $client->request('GET', 'users/find-criteria', [
        'query' => [
            'user_id' => 2,
            'email' => '[email protected]',
            'username' => 'test user'
        ],
        'http_errors' => false,
        'headers' => [
            'XF-Api-Key' => 'your-api-key'
        ]
    ]);
    $data = \GuzzleHttp\json_decode($response->getBody()->getContents(), true);
    var_dump($data);

Laravel 7
PHP:
  $response = \Illuminate\Support\Facades\Http::withHeaders([
        'XF-Api-Key' => 'your-api-key'
    ])->get('http://xenforo21.local/api/users/find-criteria', [
        'user_id' => 2,
        'email' => '[email protected]',
        'username' => 'test user'
    ]);
    $data = $response->json();
    var_dump($data);
作者
newimage
浏览
586
扩展类型
zip
文件大小
12.9 KB
首次发布
上次更新
评分 0.00 星 0 个评分
Link was Broken? Please 发送消息 给 NP 团队,我们会尽快为您处理!
支持开发者 如果您对测试满意或项目已成功盈利,可点击「更多信息」按钮,通过购买来支持开发者!

最新更新

  1. 1.0.2 - 2024-12-30
    * use canonical rather than full when building links * be explicit about building an api link

来自 newimage 的更多资源

Xon的警报改进 N
XenForo警报系统的改进集合。
俄语增强搜索对于XenForo N
  • 已推荐
XenForo增强搜索 2.1.4的翻译已完成。

相似的资源

[TH] User Criteria Extended N
[TH] User Criteria Extended 1.0.7 Patch Level 3
Heavily extends the range of available user criteria by adding opposite criteria
浏览
593
已更新
[OzzModz] User Criteria: Reacted Content A
Adds new user criteria to check if the user left reactions on the required content.
浏览
352
已更新
[OzzModz] Find All Threads/Content By User On Membercard A
Simple addon that will add links to a members threads & content on the membercard.
浏览
303
已更新
顶部