Jump to content

Confusion between GetClients and GetClientsDetails API Calls and how to retrieve phone numbers in one shot


Vander Host

Recommended Posts

Referring to these two WHMCS API Calls:

https://developers.whmcs.com/api-reference/getclients/
"Obtain the Clients that match passed criteria"

https://developers.whmcs.com/api-reference/getclientsdetails/
"Obtain the Clients Details for a specific client"
Note this function returns the client information in the top level array. This information is deprecated and may be removed in a future version of WHMCS.

What if I wanted to make one API call, to say get all client details that also includes the telephone number?

The first API call, GetClients, only returns a severely limited subset of data.

The second can return everything but I can to call it per client?

What is I have 1000s of clients, does this mean I need to make a 1000 API calls?

Any tips?

 

Edited by Vander Host
Link to comment
Share on other sites

hello @Vander Host

if you want to use API,

your solution is not good

I tip to you add a new function to API the use that function

 

first step add a php file to includes >>  api folder , name belongs to the file is function name

 

you can writ custom query in the file and return it

 

for example :

method and file name is getclinetid

<?php

use WHMCS\Database\Capsule;

if (!defined("WHMCS"))
    die("This file cannot be accessed directly");
 
try {
    $clinetsItem = Capsule::table('tblclinets')->where("phonenumber",   $_REQUEST['phonenumber'])->first();

 
 if($clinetsItem){
        $apiresults = ["result" => "success", "message" => "ok", 'clinetid' => $clinetsItem->id];

}else{
$apiresults = ["result" => "error", "message" => "not found"];
}
    
} catch (Exception $e) {
    $apiresults = ["result" => "error", "message" => "query has a problem"];

}

Example Request (Local API)

$command = 'getclinetid';
$postData = array(
    'phonenumber' => '+123456789',
);
$adminUsername = 'ADMIN_USERNAME'; // Optional for WHMCS 7.2 and later

$results = localAPI($command, $postData, $adminUsername);
print_r($results);

 

Link to comment
Share on other sites

Personally, I would skip the API for this and use internal classes / models like so:
 

use WHMCS\User\Client; 

$client = Client::find($vars['userid']);
echo $client->phoneNumber; 

Or if you want to get all clients, but only with  first name of bob:

$clients = Client::where('firstName", "bob")->get(); 

You will then get a Eloquent Collection of client objects that had the firstname as bob.  Once you have that collection, just loop the items as you need.  Eloquent is the database manager / framework WHMCS uses and though can be a pain to learn and might be a bit heavy on dependents for small projects, it does make looking stuff up and getting pretty models easier.   (I prefer classes / models / objects over arrays because they can be documented and IDEs read that for quick reference.)

Check https://classdocs.whmcs.com/8.2/WHMCS/User/Client.html though, you may want to go back a bit to like 7.10 https://classdocs.whmcs.com/7.10/WHMCS/User/Client.html to get the attributes / variable names as for some reason they removed those in 8.0+ . 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated