tinderbox Posted September 2, 2010 Share Posted September 2, 2010 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. 0 Quote Link to comment Share on other sites More sharing options...
laszlof Posted September 3, 2010 Share Posted September 3, 2010 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> 0 Quote Link to comment Share on other sites More sharing options...
tinderbox Posted September 3, 2010 Author Share Posted September 3, 2010 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. 0 Quote Link to comment Share on other sites More sharing options...
laszlof Posted September 3, 2010 Share Posted September 3, 2010 Umm, first, thats really dumb.. Why would anyone want to sort it by name? Second, if that is the intended behavior, then the docs are wrong. This is directly from: http://wiki.whmcs.com/API:Get_Clients Attributes limitstart - Which User ID to start at (default = 0) limitnum - Limit by number (default = 25) 0 Quote Link to comment Share on other sites More sharing options...
tinderbox Posted September 3, 2010 Author Share Posted September 3, 2010 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. 0 Quote Link to comment Share on other sites More sharing options...
laszlof Posted September 3, 2010 Share Posted September 3, 2010 Furthermore, the example API usage to convert the output into an array doesn't work either: At least for getclients it doesn't. foreach ($data AS $temp) { $temp = explode("=",$temp); $results[$temp[0]] = $temp[1]; } 0 Quote Link to comment Share on other sites More sharing options...
tinderbox Posted September 3, 2010 Author Share Posted September 3, 2010 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. 0 Quote Link to comment Share on other sites More sharing options...
laszlof Posted September 3, 2010 Share Posted September 3, 2010 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. 0 Quote Link to comment Share on other sites More sharing options...
tinderbox Posted September 3, 2010 Author Share Posted September 3, 2010 Right, the module I'm building is to install in another CMS to connect with WHMCS. 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.