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.

Set Custom Fields ? PHP API Library

Discussion in 'Developing, APIs and extending' started by jojoworld, Apr 18, 2012.

  1. jojoworld

    jojoworld Member

    Hello,
    I implemented the PHP API provided by Kayako and I have a problem. I can not find information in the documentation or in the comments of classes that could help me.

    I wish I could add a custom field for the creation of a ticket or update a ticket.

    Something like :

    PHP:
    $ticket $user
    ->newTicket(
    $printers_department,
    "The printer on 4th floor in building B2 doesn't print at all. Fix it quickly, please.",
    "Printer not working (example)")
    ->
    setPriority($priority_urgent)
    ->
    setCustomFields(array(=>'Value'=> 'Value'))
    ->
    create();
    I saw that the function has been integrated in the REST API, but nothing about the PHP library.

    Thank you for helping me
     
  2. Tomasz Sawicki

    Tomasz Sawicki Established Member

    It's under development as we speak. Expect the update to ship this week.
     
  3. Tomasz Sawicki

    Tomasz Sawicki Established Member

    Sorry for the delay, I had problem understanding how updating custom fields really works. I've finally cracked it up and I'm just waiting for my Kayako Trial to be fixed to perform the final tests and publish new client version.
     
  4. BlackHawkRob

    BlackHawkRob Member

  5. jojoworld

    jojoworld Member

    I would have preferred a clean solution through PHP API Tomasz which itself uses the API Kayako.

    Do you have any news on this implementation Tomasz?

    Thank you for your work
     
  6. jojoworld

    jojoworld Member

    I had not seen the new version. Thank you for having implemented;)
     
  7. jojoworld

    jojoworld Member

    I updated Kayako to 4.40.1148 and PHP library today and it don't works for me :

    Here's my PHP code :

    PHP:
    $user kyUser::get($userId);
            
    $ticket $user
            
    ->newTicket(
                
    kyDepartment::get($depChooseId),
                
    'hello',
                
    'how are you')
            ->
    create();
            
    $ticketId $ticket->getDisplayId();
            
    $ticket->getCustomField('my_customfield_name')->setValue('1234'); //Same problem with $ticket->setCustomFieldValue('my_customfield_name','1234');
            
    $ticket->update();  //Same problem with $ticket->updateCustomFields();
            
    $custom_field $ticket->getCustomField('my_customfield_name');
           
            echo 
    'Custom Value : '.$custom_field->getValue();
    Output without error :(

    HTML:
    Custom Value : 
    In the Kayako database, no insertions. I think I've a problem with the update. I tried to create another ticket object :

    PHP:
    $user kyUser::get($userId);
            
    $ticket $user
            
    ->newTicket(
                
    kyDepartment::get($depChooseId),
                
    'hello',
                
    'how are you')
            ->
    create();
            
    $ticketId $ticket->getDisplayId();
            
    $newTicket kyTicket::get($ticketId);
            
    $newTicket->getCustomField('my_customfield_name')->setValue('1234');
            
    $newTicket->update(); 
            
    $custom_field $newTicket->getCustomField('my_customfield_name');
           
            echo 
    'Custom Value : '.$custom_field->getValue();
    Same Output.

    Have I misunderstood the documentation ?
    Thank for helping me
     
  8. Tomasz Sawicki

    Tomasz Sawicki Established Member

    I've started a private conversation with you about this.
     
  9. Tomasz Sawicki

    Tomasz Sawicki Established Member

    For the record, the fix for jojoworld's problem was enabling User Editable flag for this custom field.
     
  10. CodyR

    CodyR New Member

    I'm experiencing a similar issue using the official Kayako PHP rEST client. It's not producing any errors / stack traces however it's refusing to update any custom field. I've dumbed down the code entirely and can't get it to work at all:

    PHP:
    $ticket kyTicket::get('ticket_id');
    $ticket->setCustomFieldValue('name'$value);
    $ticket->getCustomField('name')->setValue('test value');
    Any update on what's causing this (client side / software side)?
     
  11. Tomasz Sawicki

    Tomasz Sawicki Established Member

    Did you enable User Editable flag for this custom field as I said in previous post?
     
  12. CodyR

    CodyR New Member

    Yes, it still did not work although shouldn't you be able to edit custom fields via the API (as a staff member)? If not that seems like a glaring oversight.
     
  13. Tomasz Sawicki

    Tomasz Sawicki Established Member

    I also think that not setting this flag should not affect updating field value through API. I don't know if it's on purpose or an error.

    Regarding your problem:
    1. Enable debug mode by putting this after kyConfig()::set():
    PHP:
    kyConfig::get()->setDebugEnabled(true);
    2. Run your code.
    3. Start private conversation with me and send the output of PHP error log. You should of course remove all sensitive information like API URL, API Key and Secret key.
     
  14. CodyR

    CodyR New Member

    Unfortunately I cannot for the life of me find a way to PM you. However can you clarify why you'd want the error_log? The code runs successfully and isn't producing errors - it's just not updating the appropriate value. One interesting thing is if I var_dump() the kyTicket() object when setting the custom value it shows the custom field with my value - it however isn't updating it in the database (I presume).

    Please let me know the exact information you need - also where the PM button is would be good :p.
     
  15. Tomasz Sawicki

    Tomasz Sawicki Established Member

    I've started a conversation with you.

    For future reference.
    1. Click my name.
    2. Click Information tab.
    3. Click Start a Conversation.
     
  16. CodyR

    CodyR New Member

    Thanks for the help.

    As Tomasz pointed out in a PM I simply wasn't calling the updateCustomFields() method. Once I did everything worked as expected.
     
  17. Muhammad Waqas

    Muhammad Waqas New Member

    Code:
    $ticket->getCustomField('Abc')->setValue('123456');       // this may get the custom feild created in ticket and set its value
    my issue that how may i get customfeilds other than tickets
     
  18. Muhammad Waqas

    Muhammad Waqas New Member

    Code:
    //get field by name
    $custom_field = $ticket->getCustomField('<custom field name>');
    what if this custom feild is in user profile group
     
  19. Paul Arntz

    Paul Arntz New Member

    Using the Kayako interface you will see two settings pertaining to custom field editability. Below are the values I needed on each field:

    Field editable by end users = NO
    Field editable by staff = YES

    Updating custom fields

    method one
    $ticket->setCustomFieldValue('field_id', 'new field value');
    When trying up to update custom fields this did not work. I received an error: "usereditable flag is disabled for custom field [field name]"

    method two
    $ticket->getCustomField('field_id')->setValue('new field value');
    This works but there is more to it. You'll notice that if you stop at this spot you will not see an update.

    YOU MUST ALSO CALL $ticket->updateCustomFields();

    NOTE: In my case the field_id used in the above example was a random unique identifier ex. "1yzhzvjxvkhy"

    The combination of method two and calling updateCustomFields() fixed it for me.
     
    Last edited: May 19, 2017 at 3:38 PM

Share This Page