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.

Kayako PHP API and Ticket Posts

Discussion in 'Developing, APIs and extending' started by omnipcx, Jun 2, 2012.

  1. omnipcx

    omnipcx New Member

    Hello everyone, sorry if my question will be stupid :(

    I start using the API with the project Kayako PHP API available on the forge.

    When I use "kyTicket::get($ticket_number)" I see in the response:

        [posts:kyTicket:private] => Array
    0] => kyTicketPost Object
    id:protected] => 413726
    [ticket_id:protected] => 388017
    [dateline:protected] => 1338554271
    [user_id:protected] => 2237
    I would like obtain the content of the message.
    I use for that "kyTicketPost::getAll($ticket_id)" the reply like that:

    kyResultSet Object
    class_name:kyResultSet:private] => kyTicketPost
    [objects:kyResultSet:private] => Array
    0] => kyTicketPost Object
    id:protected] => 413872
    [ticket_id:protected] => 388149
    [dateline:protected] => 1338575042
    [user_id:protected] => 211
    [full_name:protected] => First Last Name
    [email:protected] => email@domain.tld
    [email_to:protected] => 
    ip_address:protected] => 
    has_attachments:protected] => 
    creator:protected] => 2
    [is_third_party:protected] => 
    is_html:protected] => 
    is_emailed:protected] => 1
    [staff_id:protected] => 
    is_survey_comment:protected] => 
    contents:protected] => Message content
    [subject:protected] => 
    attachments:kyTicketPost:private] => 
    user:kyTicketPost:private] => 
    staff:kyTicketPost:private] => 
    ticket:kyTicketPost:private] => 
    read_only:protected] => 
    I don't understand how I can extract the following value:

    With a regular Object I need to make for example:
    $ticket_messages kyTicketPost::getAll($ticket_id);
    But here I'm really lost, I've made for have all possibilities:
    I've try without success:
    $ticket_messages kyTicketPost::get($num_ticket);
    $ticket_content = $ ticket_messages  ->getContents();
    Does anyone have a working example to retrieve the contents of all messages and to display the content ([contents:protected]) in a variable?

    Thank a lot for your help
  2. Tomasz Sawicki

    Tomasz Sawicki Established Member

    Quoting from library documentation:

    As to your specific needs:
    $ticket kyTicket::get($ticket_id);
    /* @var $ticket kyTicket */
    //just the first post
    $ticket_first_post $ticket->getFirstPost();
    printf("First ticket post by %s on %s::\n%s\n\n"$ticket_first_post->getFullName(), $ticket_first_post->getDateline(), $ticket_first_post->getContents());
    //all ticket posts
    printf("All ticket posts:\n");
    foreach (
    $ticket->getPosts() as $ticket_post) {
    /* @var $ticket_post kyTicketPost */
    printf("Post by %s on %s:\n%s\n\n"$ticket_post->getFullName(), $ticket_post->getDateline(), $ticket_post->getContents());
  3. omnipcx

    omnipcx New Member

    Hello Tomasz,

    Thank for your reply and your code.

    I've read the doc, but my PHP level it's not really good ...
    I was just in difficult for the ticket posts.

    Yesterday I've change in the kyTicketPost.php all privat and protected word by public ...
    I've think it's not the best way ... That have working, but not clean ... And I've search for making with the good way :)

    Again thank for your code, that great and help me a lot, and hope that can help many others people (not php expert) :)

Share This Page