wdele Posted October 11, 2014 Share Posted October 11, 2014 Hi, How can I get the number of clients using the API? (to show it on my website) Thanks 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 11, 2014 Share Posted October 11, 2014 this won't specifically tell you how to do it via API, but if you want to use PHP to create a smarty variable, you might take a look at the thread below... http://forum.whmcs.com/showthread.php?86718-Is-there-s-smarty-syntax-to-display-total-of-clients 0 Quote Link to comment Share on other sites More sharing options...
wdele Posted October 12, 2014 Author Share Posted October 12, 2014 this won't specifically tell you how to do it via API, but if you want to use PHP to create a smarty variable, you might take a look at the thread below... http://forum.whmcs.com/showthread.php?86718-Is-there-s-smarty-syntax-to-display-total-of-clients Nice! But the problem is that I need to show it on my website (WordPress) because my main website is not powered by WHMCS. How would I go about that? 0 Quote Link to comment Share on other sites More sharing options...
TekStorm Inc - James Posted October 12, 2014 Share Posted October 12, 2014 The WHMCS API is somewhat extensible. 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted October 12, 2014 Share Posted October 12, 2014 Indirectly you can get this number probably iterating GetClients API function and counting keys but to me it seems a very bad solution. What if you have 2000 clients in your WHMCS? Spamming GetClients for every single visitor on your website and every page view sounds stupid. The best way for me is very simple. Make a php script on WHMCS, include DB connection, query database to COUNT() tblclients and print the resulting number. Now on Wordpress call this file (a get content should be fine) and job done. You have your number. This solution is better because it's faster and doesn't overload without a valid reasons WHMCS and your webserver. Personally I'll also cache this value. 0 Quote Link to comment Share on other sites More sharing options...
SeanP Posted October 12, 2014 Share Posted October 12, 2014 Create a file, in the root of your WHMCS, called "clientcount.php". Within that file, put the following code: <?php require("init.php"); // Get the client count $table = "tblclients"; $fields = "COUNT(*) AS clientcount"; $result = select_query($table,$fields); while ($data = mysql_fetch_array($result)) { $clientcount = $data['clientcount']; } echo $clientcount; ?> Now you can call this externally, by using the following code: <?php $clientcount = file_get_contents('http://www.yourdomain.com/clientcount.php'); // Full URL to clientcount.php echo 'Total Number of Clients: ' . $clientcount; ?> Hopefully, that helps. 0 Quote Link to comment Share on other sites More sharing options...
BlackNovaDesigns-Kyle Posted April 21, 2020 Share Posted April 21, 2020 (edited) As this is Googles first answer for whmcs get clients. For wordpress we wrote the following to get ours working, allowing us to tie it into a shortcode as well: //WHMCS Get Clients Shortcode //Written by Kyle - www.blacknovadesigns.co.uk function bnd_whmcs_get_clients_shortcode() { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://YOUR-DOMAIN-WHERE-WHMCS-IS/includes/api.php'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query( array( 'action' => 'GetClients', 'username' => 'API-TOKEN-ID', 'password' => 'API-TOKEN-PASSWORD, 'responsetype' => 'json', ) ) ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); $results = json_decode($response, true); curl_close($ch); echo "<h3>" .$results['totalresults']. "</h3>"; echo "<p>HAPPY CLIENTS</p>"; } add_shortcode( 'whmcsgetclients', 'bnd_whmcs_get_clients_shortcode' ); Hopefully this will help for anyone looking to do this them selves in the future. Edited April 21, 2020 by BlackNovaDesigns-Kyle 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.