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.

Active Directory User Sync Script

Discussion in 'Apps and modifications' started by Dylan Lindgren, Aug 26, 2009.

  1. Torbjörn S.

    Torbjörn S. Reputed Member

    Hi.

    I get error "class kyBase not found".
    Can someone help me out please.

    Running 4.40.1148
     
  2. Dylan Lindgren

    Dylan Lindgren Established Member

    Hi Hawkwing,

    Where do you have the script placed in relation to your Fusion PHP API? What is the config setting you're using in line 40, that is:

    Code:
    $kayakoApi = "KayakoAPI/kyIncludes.php";
    Kind regards,

    Dylan
     
  3. Torbjörn S.

    Torbjörn S. Reputed Member

    The script is placed in the same folder. Fusioninstallation/api
    $kayakoApi = "kyIncludes.php";

     
  4. Dylan Lindgren

    Dylan Lindgren Established Member

    Hi Hawkwing,

    Please have a further read of the "Installation" section on the Kayako Forge page, that should get you through this issue.

    Basically, the API directory within the Fusion installation is the actual Fusion API. My script uses the Kayako PHP API Library to connect to the Fusion API. You need to download the Kayako PHP API Library and place it on your server somewhere. You then need to point my script to the kyIncludes.php file in the Kayako PHP API Library using that setting on line 40. This is why you are getting an error about kyBase not found, because kyBase is defined in the Kayako PHP API Library and you haven't done that step of the installation yet.

    Kind regards,

    Dylan
     
  5. pallytank09

    pallytank09 Member

    Thanks for taking the time to throw this together for everyone. I am getting an error that I was hopping to get some help with.

    php ADUserSync.php


    PHP Warning: require_once(/var/www/html/custom/KayakoAPI/KayakoAPILibrary_PHP/kyIncludes.php): failed to open stream: Permission denied in /var/www/html/custom/KayakoAPI/ADUserSync.php on line 62

    PHP Fatal error: require_once(): Failed opening required '/var/www/html/custom/KayakoAPI/KayakoAPILibrary_PHP/kyIncludes.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/custom/KayakoAPI/ADUserSync.php on line 62
     
  6. rupert

    rupert New Member

    I was receiving the same "class kyBase not found".

    I had the Kayako PHP API Library 1.1 installed but noticed there is no kyBase.php file in this version. I reverted to version 1.01 and could at least import one user, but still cannot figure out what is wrong?? Below is the error I am receiving. There should be over a thousand users not "0 of 1"? Any help is appreciated...


    Updating 0 of 1 - username.........Notice: Undefined index: Position in C:\inetpub\wwwroot\ADUserSync.php on line 162Warning: curl_setopt_array() [function.curl-setopt-array]: cannot represent a stream of type MEMORY as a STDIO FILE* in C:\inetpub\wwwroot\KayakoAPI\kyBase.php on line 190Fatal error: Uncaught exception 'Exception' with message 'HTTP error: 401' in C:\inetpub\wwwroot\KayakoAPI\kyBase.php:198 Stack trace: #0 C:\inetpub\wwwroot\KayakoAPI\kyBase.php(246): kyBase::processRequest('/Base/User', 'PUT', Array, Array) #1 C:\inetpub\wwwroot\KayakoAPI\kyObjectBase.php(171): kyBase::_put(Array, Array) #2 C:\inetpub\wwwroot\ADUserSync.php(165): kyObjectBase->update() #3 {main} thrown in C:\inetpub\wwwroot\KayakoAPI\kyBase.php on line 198
     
  7. rupert

    rupert New Member

    After reading previous posts by Larry Yu, I followed the same kybase.php edit and now receive the error below (same results as Larry)


    Updating 0 of 1 - XXXXXXXXX.........Fatal error: Uncaught exception 'Exception' with message 'HTTP error: 405' in C:\inetpub\wwwroot\KayakoAPI\kyBase.php:198 Stack trace:

    #0 C:\inetpub\wwwroot\KayakoAPI\kyBase.php(246): kyBase::processRequest('/Base/User', 'PUT', Array, Array)
    #1 C:\inetpub\wwwroot\KayakoAPI\kyObjectBase.php(171): kyBase::_put(Array, Array)
    #2 C:\inetpub\wwwroot\ADUserSync.php(166): kyObjectBase->update() #3 {main} thrown in C:\inetpub\wwwroot\KayakoAPI\kyBase.php on line 198
     
  8. pallytank09

    pallytank09 Member

    Is it possible to user this to sync address information from a user in AD into Custom fields in the users profile in kayako?
     
  9. Anita_Efor

    Anita_Efor New Member

    Hi!

    When we try to execute ADUserSync.php, we receive that error:

    Catchable fatal error: Argument 1 passed to kyUser::setUserOrganization() must be an instance of kyUserOrganization, null given, called in /mypath/ADUserSync.php on line 175 and defined in /mypath/KayakoAPI/kyUser.php on line 253

    Line 175 ADUserSync.php:

    ->setUserOrganization($organization)
    Line 253 kyUser.php:
    public function setUserOrganization(kyUserOrganization $user_organization) {
    $this->user_organization_id = $user_organization->getId();
    $this->user_organization = $user_organization;
    return $this;
    }

    My AdUserSync version is the latest (1.1), but we can't use the latest version of PHP API REST Library because it doesn't contain the file kyBase.php. So we are using the version 1.0.1 instead of 1.1. I have seen another ticket with the same problem, but I´m not using the same version, I use the latest.

    What Can We Do?

    Thanks
     
  10. ds289

    ds289 Established Member

    Same issue here. kyBase.php is not present in PHP API Library v1.1.

    This project is really somewhat critical to us to begin using Fusion. Have latest Fusion 4.50 installed if that matters.
     
  11. ds289

    ds289 Established Member

    Well, I got somewhere with this issue. I asked about it in the Forge for PHP API project. http://forge.kayako.com/issues/101

    The functionality has moved.

    In AdUserSync.php, I made the following change:

    PHP:
    // Connect to the KayakoAPI
    require_once($kayakoApi);
    kyConfig::set(new kyConfig($kayakoApiURL$kayakoApiKey$kayakoSecret));
    Change is only to the 3rd line above.

    The script actually runs now. I still have to sort out some AD lookup/filter issues, so I'm not sure if its 100% working yet. Can anyone else who ran into the kyBase issue test with this change?
     
  12. ds289

    ds289 Established Member

    I can confirm that my above change works with newest PHP API library.
     
  13. Torbjörn S.

    Torbjörn S. Reputed Member

    I get the script running, It gets the users from AD but id doesnt disable them if i remove them from the group. And also, it only seams like the first one is imported.
    running 4.50.1636
     
  14. ds289

    ds289 Established Member

    Argh. New problem - AD (any LDAP directory implementation really) has a page size limit of 1000 results. I do not want to modify registry to increase the page size - this is not a best practice. Does anyone have any insight into whether Dylan's script can be modified to allow for pagination support? My PHP skills are not there.
     
  15. scott2020

    scott2020 New Member

    I love this script, but it was crashing a lot for me. I made the changes indicated throughout this thread and added a few things. I have over 2000 people in my AD and some do not have email. The script would crash on those, so I added a check around line 117 in the area where phone and description are checked. If there is no email address, I hard coded a dummy email. The disabling of accounts was also crashing, so I commented that out. The filter messed with me a lot, so I ended up with:

    Code:
    $filter = "(&(objectclass=user)(objectcategory=person))";
    
    Don't try leaving the filter blank. The script won't work without it. I also had to set:

    Code:
    ldap_set_option($ad, LDAP_OPT_REFERRALS, 0);
    Here's the blank email code.

    Code:
                         
     
    if (!isset($adlookup[$i]["mail"]))
                            {
                                    $email = "noemail@something.com";
                            }
                            else
                            {
                                    $email = strtolower($adlookup[$i]["mail"][0]);
                            }
    
     
  16. ds289

    ds289 Established Member

    To expand on my most recent post in this thread, I eventually got a developer to modify the code to support full pagination. We have almost 6000 users to import. It's somewhat specific to our needs and AD structure and not super clean, so I don't really want to post our code changes. But, it IS possible. :)
     
  17. Nick Baccala

    Nick Baccala New Member

    Any hints? =)
     
  18. Nick Baccala

    Nick Baccala New Member

    For people who have asked or wondered about inserting AD attributes into User Object custom fields please upvote/watch the following:

    http://dev.kayako.com/browse/SWIFT-3188

    Apparently even though they added functionality to insert ticket object custom fields from the API, they left out inserts into user object custom fields. =/
     
  19. Yizi

    Yizi Member

    I get the following error when I run the script.

    Code:
    Notice: Undefined index: mail in C:\www\ADUserSync.php on line 81
     
    Notice: Undefined index: mailnickname in C:\www\ADUserSync.php on line 83
     
    Notice: Undefined index: mail in C:\www\ADUserSync.php on line 81
     
    Notice: Undefined index: mailnickname in C:\www\ADUserSync.php on line 83
    Updating 0 of 4 - John.Smith.........
    Fatal error: Uncaught exception 'kyException' with message 'HTTP error: 401' in C:\www\KayakoAPI\kyRESTClient.php:185
    Stack trace:
    #0 C:\www\KayakoAPI\kyRESTClient.php(229): kyRESTClient->processRequest('/Base/User', 'PUT', Array, Array, Array)
    #1 C:\www\KayakoAPI\kyObjectBase.php(278): kyRESTClient->put('/Base/User', Array, Array)
    #2 C:\www\ADUserSync.php(143): kyObjectBase->update()
    #3 {main}
      thrown in C:\www\KayakoAPI\kyRESTClient.php on line 185
     
  20. Yizi

    Yizi Member

    BUMP
     

Share This Page