1. Kayako Download customers: we will continue to develop and support Kayako Download beyond July 2017, alongside the new Kayako for existing customers.

    Find out more.

  2. The forum you are viewing relates to Kayako Classic. If you signed up or upgraded to the new Kayako (after the 4th July 2016), the information in this thread may not apply to you. You can visit the forums for the new Kayako here.

PHP API - kyUser::getAll() not returning all users

Discussion in 'Developing, APIs and extending' started by Dylan Lindgren, Apr 23, 2012.

  1. Dylan Lindgren

    Dylan Lindgren Established Member

    Hi all,

    I am the developer of the Active Directory User Sync project on Kayako Forge. The script uses the Kayako PHP API to add/update/remove users. I am attempting to troubleshoot a problem with my script and I believe the issue lies not with my script but instead with either the Fusion API or the PHP API.

    I was getting HTTP error 400 messages on the "insert user" stage of my script which happens after the update user stage. Upon investigation I found that not all of the users were being returned by the PHP API function kyUser::getAll() and thus the users which that function did not bring back are mistakenly being thought of as new users, and when the script tries to add that user it I assume generates the HTTP error 400 as the user actually does already exist in Fusion.

    The error seems to have started occurring ever since I upgraded Fusion from 4.40.750 to 4.40.1079.

    Can someone with involvement with the Kayako API or PHP API please let me know if this is a genuine bug that needs to be fixed, or if I'm doing something wrong.

    Thanks in advance,

  2. ad_amin

    ad_amin Established Member

    Hi Dylan,
    PHP API uses REST API for receiving data. And GET function of the REST API has a fetch limit set to 1000. That's why you're not receiving all users.

    The workaround is to call the getAll function in a loop (with 1000 users interval) - which is unfortunately terribly slow...
  3. Dylan Lindgren

    Dylan Lindgren Established Member

    Ah excellent, thanks for that. I didn't know about that limit. Definitely it is a bit slow, but the AD User Sync script only really needs to be run like once a day at most and should be automated via a scheduled task so efficiency isn't really that important. If it takes a few minutes to run it's no big deal.
  4. Dylan Lindgren

    Dylan Lindgren Established Member

    Thanks for your help, I got it working with the following code. This pulls users with the first 1000 user ID's and then loops and pulls the next 1000 and keeps doing it until the stuff pulled hits 0 (end of table).

    // Populate the Kayako Users Array
    $i 1000;
    do {
    $kyUsers kyUser::getAll($i 1000$i);
    $lastcount count($kyUsers);
        foreach (
    $kyUsers as $user) {
    // We are using email addresses to compare the users. Sometimes the emails are capitalised etc, so lets convert it to lowercase to ensure the comparison works. 
    $fusionUsers[strtolower($user->getEmail())] = array("FullName" => $user->getFullName(), "Phone" => $user->getPhone(), "Email" => strtolower($user->getEmail()), "Organization" => $user->getUserOrganizationID(), "Id" => $user->getId());
    $i $i 1000;
    } while (
    $lastcount 0);

Share This Page