Jump to content

API's getclients call doesn't return results in 'id' order?


tinderbox

Recommended Posts

I'm building a module for another CMS to display data from WHMCS in its pages. As a test function, I'm starting with the getclients call, but as I try to use the limitstart and limitnum attributes to restrict the amount of data returning, I've noticed a problem.

 

When not using either attributes to limit the request, the XML file that returns the list of clients doesn't list them in order of their IDs (starting with 0). For some reason, it seems to list them in alphabetical order using the first name. Furthermore, it's not just a formatting issue. The attributes restrict the request as if the first one listed has the ID 0, although it actually has the ID 2. The second one behaves with the attribute limitstart as if its ID were 1, though it's actually 4, and so on.

 

Can anyone else confirm this? Am I doing something wrong here, or is this a bug? I've already searched the forums and docs, but the resources on the API are pretty scant to be honest.

 

'Twould be awesome to get a comment from Matt here.

Link to comment
Share on other sites

This should probably be in the bug forum.. limitstart is definitely not working as it should. I did a quick test with the following code:

 


<?php

$url = "https://whmcs.url.com/includes/api.php"; # URL to WHMCS API file
$username = "admin";
$password = "password";

$postfields["username"] = $username;
$postfields["password"] = md5($password);
$postfields["action"] = "getclients";
$postfields["limitstart"] = "10";
$postfields["limitnum"] = "2";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$data = curl_exec($ch);
curl_close($ch);

$data = explode(";",$data);
print_r($data);
?>

 

You would assume that it would start at UID 10.. but in fact, it does not.. Heres the output:

 


<?xml version="1.0" encoding="utf-8"?>
<whmcsapi version="4.3.1">
<action>getclients</action>
<result>success</result>
<totalresults>27919</totalresults>
<startnumber>10</startnumber>
<numreturned>2</numreturned>
<clients>
<client>
<id>22046</id>
<firstname>XXXXXX</firstname>
<lastname>XXXXXX</lastname>
<companyname>XXXXXX</companyname>
<email>XXXXXX</email>
</client>
<client>
<id>6534</id>
<firstname>XXXXXX</firstname>
<lastname>XXXXXX</lastname>
<companyname>XXXXXX</companyname>
<email>XXXXXX</email>
</client>
</clients>

Link to comment
Share on other sites

Yeah, I also filed a support request with similar info to this post, and Matt's response was thus:

I can confirm the sort order is by name rather than ID but the limitstart variable is where to start at, not an ID, so start at record 0 in the results, record 10, 25, etc.. and limitnum is the number to return so "0,25" is the default.

So... there's that. Apparently this is how its intended to be, but that just doesn't make any sense. Why would it be ordered by name? One can never anticipate which record they'll be targeting by using 'limitstart' since new clients and deleted clients change that listing completely. Weird.

Link to comment
Share on other sites

Yeah, the more I've gotten into working with the API, the more frustrated I get. They're pretty poorly documented, and unexpected behavior manifests itself pretty routinely.

 

I made a plea for the default behavior to be sorting by User ID, as everyone in the world would expect. We'll see.

Link to comment
Share on other sites

Yeah, it took me 2 hours to figure out where to ignore the example API docs. The Name/Value Pairs section on the about page is completely wrong; I can't find any of the functions returned as a string. Worthless.

 

I'm building a module in another CMS that interacts with this API, and now I'm worried that I can't rely on it. For the amount we're all paying for WHMCS, you'd think the docs would be stellar. Especially given that anyone trying to add value to WHMCS with a third-party module needs solid API docs to work with.

Link to comment
Share on other sites

Yeah, it took me 2 hours to figure out where to ignore the example API docs. The Name/Value Pairs section on the about page is completely wrong; I can't find any of the functions returned as a string. Worthless.

 

I'm building a module in another CMS that interacts with this API, and now I'm worried that I can't rely on it. For the amount we're all paying for WHMCS, you'd think the docs would be stellar. Especially given that anyone trying to add value to WHMCS with a third-party module needs solid API docs to work with.

 

Well, You do not need to use the API to build modules. They're mostly for allowing external applications to communicate with them.

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