REST API client in PHP

Discussion in 'Modules, plugins and modifications' started by Tomasz Sawicki, Apr 8, 2011.

?

Was the client helpful?

Yes 5 vote(s) 71.4%
I failed to get it working 2 vote(s) 28.6%
Not really 0 vote(s) 0.0%
  1. Hi,

    I have implemented easy to use PHP client to Kayako v4 REST API. You can get it from https://github.com/Furgas/Kayako-REST-API-Client. Examples are included.

    In order to use some of its features you need to patch Kayako installation. Patch is included and everything is described in README. I hope future updates of Kayako will include some of these changes (as most of them are very obvious).

    Any comments and contributions are welcome.
    • Kayako Staff

    Varun Shoor Chief Kayaker

    Can you list me the changes you made? I cant dig up on em right now but we are open to implementing any improvements!
  2. Chris Boulton Established Member

    Tomasz's changes seem to focus around a lot of consistency - and he's picked up on things I've completely glossed over, including ordering of ticket posts, etc. Definitely going to apply those changes to our installation.

    Varun, I've got a bunch of changes here as well that I'm hoping not to have to maintain in the future. What's the best way to provide them?
    • GET /Ticket/Count - method to return the total number of tickets matching a specific criteria
    • GET /Ticket/ListAll - enhancements adding the ability to specify a sort order/direction, limit the number of results and filter by department, status, priority, owner, and user ID. Also the ability to filter by email address, similar to how the front end searches for tickets
    • POST /Ticket - ability to create a ticket by just supplying an email address/full name combination rather than a user ID - a user is created on the fly, similar to how ticket submission via email works
    • GET /CustomField/ListAll - fetch all custom fields matching certain criteria (basically column in the database) or custom fields of one or more custom field group types
    • GET /CustomField/[ID] - retrieve a single custom field, along with all group information
    • GET /CustomFieldGroup/ListAll - fetch all custom field groups (or filter them by group type)
    • GET /CustomFieldGroup/[ID] - retrieve a single custom field group
    • GET /CustomFieldValue/[type]/[ID] - retrieve custom fields associated with the given entry (StaffTicket, UserTicket, StaffUserTicket, News, etc). Also allows for fetching all ticket related fields for a certain ticket in one hit
    • POST /CustomFieldValue/[type]/[ID] - save custom fields for a given entry (same type values as above). This one was hacked together in a few minutes, so I may have missed some validation here
  3. Varun: I've attached the patch to this ticket: http://dev.kayako.com/browse/SWIFT-1279

    In fact, Chris's changes goes far beyond my changes and I agree that API should be extended with:
    1. Ability to search objects using different criterias, I would do that by introducing new controller method Search (ex: Base/User/Search) to maintain backward compatibility. Examples:
    - search user by email: e=/Base/User/Search/email/user@example.com (more RESTful) or e=/Base/User/Search&email=user@example.com
    - search user by group and enabled flag, sorted by full name: e=/Base/User/Search/usergroupid/1/isenabled/1/sort/fullname (order of search parameters is not fixed like in ListAll) or /Base/User/Search&usergroupid=1&isenabled=1&sort=fullname
    2. Ability to count objects (similar to Search). Example:
    - count users with certain group and enabled flag: e=/Base/User/Count/isenabled/1/usergroupid/1 or /Base/User/Count&isenabled=1&usergroupid=1
    3. Making ticket time track separate object (not a note) because it is very different from a note. Also there should be POST, PUT and DELETE methods for time tracks.
    4. Custom fields in tickets (getting and setting).
    • Kayako Staff

    Varun Shoor Chief Kayaker

    We have planned for the API extension for the next build, lets use this thread as a feedback sharing. Let me know if something else is missing because we will be referring to this when the time for implementation comes!

    Thanks!
  4. aiso Reputed Member

    What version of Kayako build will this be?
    • Kayako Staff

    Jamie Edwards Chief Limey

    Patch file if you have one? Thanks!
  5. Chris Boulton Established Member

    I want to clean it up a bit first, but I'll definitely be providing one. Expect something some time around the middle of next week after I've completed our migration.

    I have a bit of a different belief in filtering (/Ticket/ListAll?departmentid=X), so I've implemented that instead of the default. Because I've also got filtering on so many different fields, a query string made the most sense for me.

    Anyway, I'll stop stealing Tomasz's thunder, from his PHP client library. :)
  6. I see 1 vote for "I failed to get it working":) Don't hesitate to describe what was the problem, so I can help you or fix a bug.
  7. aiso Reputed Member

    I would like to vote for the get user info by email via GET as well, that would make my WHMCS integration code much happier. :)
  8. Jason Morrison New Member

    I voted "I failed to get it working" -- but it turns out it was just the Example.php kyTicket::setDefaults (I didn't have a 4 status in my default install) so I was getting a 400 error. Figured that out, and all is good. Please change my vote to a Yes, it's helpful.

    One question though: I am running ionCube version 4.01.204 and I don't know how to apply the patch. How is not applying the patch going to affect the use of the client? So far I didn't have a problem creating a new ticket.
  9. Without the patch you won't be able to delete ticket notes and ticket posts. Also if you want to display ticket posts and notes in external application they won't be automatically sorted by creation date, but you can always do it yourself. Send me a private message if you still want to apply the patch, maybe I will be able to help.

    I've changed parts of README and example.php concerning the patch and setting defaults for new tickets.
    Thank you for your input.
  10. Ryan Crosby New Member

    Is there a patch file available for Chris's changes, or will they be in an upcoming update? I was tasked with installing Kayako and integrating it with our current infrastructure, and this would be invaluable.

    Ryan
  11. Ian Saunders Member

    Hi Chris,

    Could you pass on your changes for the CustomFieldValues? It doesn't matter to myself if the code is a bit messy, can tidy it up as we go!

    Cheers,
    Ian
  12. monker Member

    I know this is a total newb question, but is there a how to? I have never made an API or even worked with one. I under stand the code but how do you submit? is it as simple as posting?
    • Kayako Staff

    Jamie Edwards Chief Limey

    There is one on the front of the GitHub project page
  13. API is basically some interface an application (in this case Kayako) exposes to the outside world, so you can do something (ex. post a ticket) from external application. Kayako exposes its API through RESTful web service (simple HTTP GET, POST, PUT, DELETE methods with some parameters). If you want to know what can be done with this API Rest API Wiki is the starting point. Of course to use it you must write some code which makes these HTTP requests and parses the response.

    If you don't want to write your own API client you can use clients other people shared. This thread is about one of them that you can use in PHP applications (here is another one). Recently Evan Leis published his Python client. I'm sure there is also clients for other languages - maybe someone else will post links to them.

    So, the basic question is what is the programming language of the application you want to call API from?
  14. monker Member

    It will be PHP.
  15. monker Member

    How do you run the patch in windows?
  16. If you're talking about patch mentioned in the PHP API Client, then you don't need it if you're not going to delete ticket post or ticket notes.
    In case of problems please start a conversation with me.

Share This Page