JavierCN Posted September 26, 2023 Share Posted September 26, 2023 (edited) Hello everyone, I need to retrieve a list of all clients that a user can manage through the WHMCS API. I've searched the documentation and community discussions, but unfortunately, I haven't been able to find a solution. The goal is to fetch the clients ids associated with a user id. Thank you in advance for your assistance! Javier Edited September 26, 2023 by JavierCN 0 Quote Link to comment Share on other sites More sharing options...
pRieStaKos Posted September 30, 2023 Share Posted September 30, 2023 You need to use GetUsers. I you see the example results, you get his clients. 1 Quote Link to comment Share on other sites More sharing options...
JavierCN Posted October 2, 2023 Author Share Posted October 2, 2023 Hello: I see that GetUsers get all users, is it possible to retrieve just a specified user ID ? 0 Quote Link to comment Share on other sites More sharing options...
Solution JavierCN Posted October 11, 2023 Author Solution Share Posted October 11, 2023 (edited) I answer myself, with the aid of the WHMCS support team and @pRieStaKos: The GetUsers API command has a field to filter by email. It can be used to retrieve the user you want. This command will display all the clients managed by the user. Currently, there is no option to filter users by ID to get their assigned clients. Edited October 11, 2023 by JavierCN Full explanation 0 Quote Link to comment Share on other sites More sharing options...
techwthquestion Posted October 11, 2023 Share Posted October 11, 2023 Please try this code. <!DOCTYPE html> <html> <head> <title>Fetch Client Details by User ID</title> </head> <body> <h1>Fetch Client Details by User ID</h1> <form method="post"> Enter User ID: <input type="text" name="userId"> <input type="submit" value="Fetch Client Details"> </form> <?php if ($_SERVER["REQUEST_METHOD"] == "POST") { $whmcsUrl = "https://whmcs.domain.com/"; $api_identifier = "your_api_credential_identifier"; $api_secret = "your_api_credential_secret"; $userID = $_POST["userId"]; $postfields = array( 'identifier' => $api_identifier, 'secret' => $api_secret, 'action' => 'GetClientsDetails', 'clientid' => $userID, // Set the User ID from the form 'responsetype' => 'json', ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $whmcsUrl . 'includes/api.php'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postfields)); $response = curl_exec($ch); if (curl_error($ch)) { die('Unable to connect: ' . curl_errno($ch) . ' - ' . curl_error($ch)); } curl_close($ch); $jsonData = json_decode($response, true); if ($jsonData['result'] == 'success') { $clientDetails = $jsonData['client']; $firstname = $clientDetails['firstname']; $lastname = $clientDetails['lastname']; $email = $clientDetails['email']; echo '<h2>Client Details for User ID ' . $userID . '</h2>'; echo 'First Name: ' . $firstname . '<br>'; echo 'Last Name: ' . $lastname . '<br>'; echo 'Email: ' . $email . '<br>'; } else { echo 'API call failed: ' . $jsonData['message']; } } ?> </body> </html> 0 Quote Link to comment Share on other sites More sharing options...
JavierCN Posted October 13, 2023 Author Share Posted October 13, 2023 Hello @techwthquestion: The ClientID is not the same than the UserID, so the query GetClientsDetails cannot be used to filter by the UserID. Results: { "result": "success", "userid": 1147, "client_id": 1147, "id": 1147, "owner_user_id": 2, ... As you see, the owner_user_id is not the same as "client_id" (I guess that the field "userid" is maintained equal to client_id for compatibility purposes). In that query, you can filter by ClientID, and you can see the user IDs that have permissions over the client, but I need a command that do the opposite (filter by UserID to get the Clients managed by that user). Thank you anyway. 0 Quote Link to comment Share on other sites More sharing options...
Burti Posted November 8 Share Posted November 8 We need GetUserClients end-point... U can ValidateLogin via email password. U get userid but u dont know user_clients.*.id 😄 .... funny 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted November 9 Share Posted November 9 23 hours ago, Burti said: U get userid but u dont know user_clients.*.id You get that with the GetUsers end point: https://developers.whmcs.com/api-reference/getusers/ { "result": "success", "totalresults": 1, "startnumber": 0, "numreturned": 1, "users": [ { "id": 1, "firstname": "John", "lastname": "Smith", "email": "john.smith@example.net", "datecreated": "2020-12-15 15:29:49", "validationdata": "", "clients": [ { "id": 1, "isOwner": true } ] } ] } 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.