Set Ticket Custom Field (JAVA)

Discussion in 'Developing, APIs and extending' started by Tomas Rehak, Jul 9, 2012.

  1. Tomas Rehak

    Tomas Rehak New Member

    Hello,

    I’ve been struggling with the following problem for couple of days and would really appreciate your help for I have no idea what’s wrong.
    Basically, I am trying to set ticket custom field to a certain value (following doc on http://wiki.kayako.com/display/DEV/REST - TicketCustomField )

    1) At first, I retrieve custom fields:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <customfields>
    <customfield customfieldid="5" customfieldgroupid="3" title="BUTR" fieldtype="2" fieldname="1tbxz3gnar22" defaultvalue="" isrequired="0" usereditable="0" staffeditable="1" regexpvalidate="" displayorder="1" encryptindb="0" description="" />
    <customfield customfieldid="6" customfieldgroupid="2" title="Operating system" fieldtype="9" fieldname="qms8sjd9cqvx" defaultvalue="" isrequired="0" usereditable="1" staffeditable="1" regexpvalidate="" displayorder="20" encryptindb="0" description="" />
    <customfield customfieldid="9" customfieldgroupid="5" title="Mobile Platform" fieldtype="9" fieldname="gym3b8ulghdq" defaultvalue="" isrequired="1" usereditable="0" staffeditable="1" regexpvalidate="" displayorder="21" encryptindb="0" description="" />
    <customfield customfieldid="17" customfieldgroupid="5" title="Mobile Product" fieldtype="9" fieldname="q0iuaw25uu2g" defaultvalue="" isrequired="1" usereditable="0" staffeditable="1" regexpvalidate="" displayorder="22" encryptindb="0" description="" />
    <customfield customfieldid="21" customfieldgroupid="9" title="GUID" fieldtype="1" fieldname="ajmxahfjrntu" defaultvalue="" isrequired="1" usereditable="1" staffeditable="1" regexpvalidate="" displayorder="23" encryptindb="0" description="" />
    <customfield customfieldid="25" customfieldgroupid="9" title="CommunityIQ data" fieldtype="2" fieldname="0q2r703dw67b" defaultvalue="" isrequired="0" usereditable="1" staffeditable="1" regexpvalidate="" displayorder="24" encryptindb="0" description="" />
    <customfield customfieldid="29" customfieldgroupid="9" title="Device log" fieldtype="11" fieldname="o7yzrfm8blrm" defaultvalue="" isrequired="0" usereditable="1" staffeditable="1" regexpvalidate="" displayorder="25" encryptindb="0" description="" />
    <customfield customfieldid="33" customfieldgroupid="9" title="System dump" fieldtype="11" fieldname="49xf3eawxo79" defaultvalue="" isrequired="0" usereditable="1" staffeditable="1" regexpvalidate="" displayorder="26" encryptindb="0" description="" />
    <customfield customfieldid="37" customfieldgroupid="13" title="Feedback type" fieldtype="6" fieldname="zrdrdpwcm24l" defaultvalue="" isrequired="0" usereditable="1" staffeditable="1" regexpvalidate="" displayorder="27" encryptindb="0" description="" />
    </customfields>
    2) Then I retrieve custom fields options

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <customfieldoptions>
    <option customfieldoptionid="31" customfieldid="6" optionvalue="Windows" displayorder="1" isselected="0" parentcustomfieldoptionid="0" />
    <option customfieldoptionid="53" customfieldid="6" optionvalue="Warp" displayorder="1" isselected="0" parentcustomfieldoptionid="52" />
    ..
    ..
    ..
    <option customfieldoptionid="40" customfieldid="6" optionvalue="98" displayorder="9" isselected="0" parentcustomfieldoptionid="31" />
    <option customfieldoptionid="41" customfieldid="6" optionvalue="95" displayorder="10" isselected="0" parentcustomfieldoptionid="31" />
    <option customfieldoptionid="42" customfieldid="6" optionvalue="---" displayorder="11" isselected="1" parentcustomfieldoptionid="31" />
    </customfieldoptions>
     
    <?xml version="1.0" encoding="UTF-8"?>
    <customfieldoptions>
    <option customfieldoptionid="61" customfieldid="9" optionvalue="Android" displayorder="1" isselected="0" parentcustomfieldoptionid="0" />
    ..
    ..
    ..
    <option customfieldoptionid="93" customfieldid="9" optionvalue="---" displayorder="8" isselected="1" parentcustomfieldoptionid="0" />
    </customfieldoptions>
     
    <?xml version="1.0" encoding="UTF-8"?>
    <customfieldoptions>
    <option customfieldoptionid="113" customfieldid="17" optionvalue="avast! Mobile Security" displayorder="1" isselected="0" parentcustomfieldoptionid="0" />
    <option customfieldoptionid="117" customfieldid="17" optionvalue="latest release" displayorder="1" isselected="0" parentcustomfieldoptionid="113" />
    ..
    ..
    ..
    <option customfieldoptionid="137" customfieldid="17" optionvalue="I don't know" displayorder="3" isselected="0" parentcustomfieldoptionid="0" />
    <option customfieldoptionid="141" customfieldid="17" optionvalue="---" displayorder="8" isselected="1" parentcustomfieldoptionid="0" />
    </customfieldoptions>
     
    <?xml version="1.0" encoding="UTF-8"?>
    <customfieldoptions>
    <option customfieldoptionid="145" customfieldid="37" optionvalue="Feedback" displayorder="1" isselected="1" parentcustomfieldoptionid="0" />
    <option customfieldoptionid="149" customfieldid="37" optionvalue="Feature request" displayorder="2" isselected="0" parentcustomfieldoptionid="0" />
    <option customfieldoptionid="153" customfieldid="37" optionvalue="Bug report" displayorder="3" isselected="0" parentcustomfieldoptionid="0" />
    <option customfieldoptionid="157" customfieldid="37" optionvalue="Crash report" displayorder="4" isselected="0" parentcustomfieldoptionid="0" />
    </customfieldoptions>
     
    <?xml version="1.0" encoding="UTF-8"?>
    <customfieldoptions>
    <option customfieldoptionid="61" customfieldid="9" optionvalue="Android" displayorder="1" isselected="0" parentcustomfieldoptionid="0" />
    <option customfieldoptionid="77" customfieldid="9" optionvalue="1.x" displayorder="1" isselected="0" parentcustomfieldoptionid="61" />
    ..
    ..
    ..
    <option customfieldoptionid="81" customfieldid="9" optionvalue="3.x" displayorder="5" isselected="0" parentcustomfieldoptionid="61" />
    <option customfieldoptionid="85" customfieldid="9" optionvalue="4.x" displayorder="6" isselected="0" parentcustomfieldoptionid="61" />
    <option customfieldoptionid="93" customfieldid="9" optionvalue="---" displayorder="8" isselected="1" parentcustomfieldoptionid="0" />
    </customfieldoptions>
     
    <?xml version="1.0" encoding="UTF-8"?>
    <customfieldoptions>
    <option customfieldoptionid="113" customfieldid="17" optionvalue="avast! Mobile Security" displayorder="1" isselected="0" parentcustomfieldoptionid="0" />
    <option customfieldoptionid="117" customfieldid="17" optionvalue="latest release" displayorder="1" isselected="0" parentcustomfieldoptionid="113" />
    <option customfieldoptionid="129" customfieldid="17" optionvalue="latest release" displayorder="1" isselected="0" parentcustomfieldoptionid="125" />
    <option customfieldoptionid="121" customfieldid="17" optionvalue="latest beta" displayorder="2" isselected="0" parentcustomfieldoptionid="113" />
    <option customfieldoptionid="125" customfieldid="17" optionvalue="avast! Anti Theft" displayorder="2" isselected="0" parentcustomfieldoptionid="0" />
    <option customfieldoptionid="133" customfieldid="17" optionvalue="latest beta" displayorder="2" isselected="0" parentcustomfieldoptionid="125" />
    <option customfieldoptionid="137" customfieldid="17" optionvalue="I don't know" displayorder="3" isselected="0" parentcustomfieldoptionid="0" />
    <option customfieldoptionid="141" customfieldid="17" optionvalue="---" displayorder="8" isselected="1" parentcustomfieldoptionid="0" />
    </customfieldoptions>
     
    <?xml version="1.0" encoding="UTF-8"?>
    <customfieldoptions>
    <option customfieldoptionid="145" customfieldid="37" optionvalue="Feedback" displayorder="1" isselected="1" parentcustomfieldoptionid="0" />
    <option customfieldoptionid="149" customfieldid="37" optionvalue="Feature request" displayorder="2" isselected="0" parentcustomfieldoptionid="0" />
    <option customfieldoptionid="153" customfieldid="37" optionvalue="Bug report" displayorder="3" isselected="0" parentcustomfieldoptionid="0" />
    <option customfieldoptionid="157" customfieldid="37" optionvalue="Crash report" displayorder="4" isselected="0" parentcustomfieldoptionid="0" />
    </customfieldoptions>
     
    
    3) Finally I try to set ticket custom field to some value with the following request:

    URL: https://dev.support.avast.com/api/index.php?e=/Tickets/TicketCustomField/290709

    Code:
    DefaultHttpRequest(chunked: false)
    POST /api/index.php?e=/Tickets/TicketCustomField/290709 HTTP/1.1
    Host: dev.support.avast.com
    Content-Length: 264
    Content-Type: application/x-www-form-urlencoded
    
    Post content:

    Code:
    ajmxahfjrntu=testtesttestvalue&apikey=8acaa54c-02cb-5194-65a3-0710a764c374&salt=e33f5325484cd17dfeb824a3facec6cf62bd36e8762436791946b0d7ce635d0c&signature=eyhzaD7YQ0bpeJibJ3YFVHpz1gUHdarjHthCCyvRLS0%3D
    
    The response I get :

    Code:
    <div style="BACKGROUND: #f8ebeb; FONT: 13px Trebuchet MS, Verdana, Helvetica, Arial; BORDER: 1px SOLID #751616; PADDING: 10px; MARGIN: 5px;"><font color="red">[Notice]: Uninitialized string offset: 0 (api/class.Controller_TicketCustomField.php:229)</font></div>
    <?xml version="1.0" encoding="UTF-8"?>
    <customfields>
    <group id="2" title="Details">
    <field id="6" title="Operating system" type="9" name="qms8sjd9cqvx" />
    </group>
    <group id="5" title="mobile details">
    <field id="9" title="Mobile Platform" type="9" name="gym3b8ulghdq" />
    <field id="17" title="Mobile Product" type="9" name="q0iuaw25uu2g" />
    </group>
    <group id="13" title="AMS-Feedback-Customer">
    <field id="37" title="Feedback type" type="6" name="zrdrdpwcm24l" />
    </group>
    <group id="3" title="internal">
    <field id="5" title="BUTR" type="2" name="1tbxz3gnar22" />
    </group>
    <group id="9" title="AMS-Feedback-Staff">
    <field id="21" title="GUID" type="1" name="ajmxahfjrntu" />
    <field id="25" title="CommunityIQ data" type="2" name="0q2r703dw67b" />
    <field id="29" title="Device log" type="11" name="o7yzrfm8blrm" />
    <field id="33" title="System dump" type="11" name="49xf3eawxo79" />
    </group>
    </customfields>
    
    Btw 10000 characters post limit to this forum???
     
  2. Tomasz Sawicki

    Tomasz Sawicki Established Member

    1. You must send all required fields values in POST request (you didn't).
    2. You must enable field User Editable flag to set its value through API (review your settings).
     
  3. Tomas Rehak

    Tomas Rehak New Member

    Thank you for your reply!

    I've checked that "User Editable flag" is set.

    I've been playing with PHP API and I am unable to set the value from it as well.
    With some added debugging, PHP API emits this:

    Path, method, ticketID, ticket vars and finally POST request body

    Code:
    string(26) "/Tickets/TicketCustomField"
    string(4) "POST"
    array(1) {
      ["ticketid"]=>
      int(290709)
    }
    array(6) {
      ["1tbxz3gnar22"]=>
      string(0) ""
      ["ajmxahfjrntu"]=>
      string(13) "TestGUIDtest1"
      ["0q2r703dw67b"]=>
      string(0) ""
      ["apikey"]=>
      string(36) "8acaa12c-02cb-5194-6323-098h6dc4c374"
      ["salt"]=>
      int(1009147916)
      ["signature"]=>
      string(44) "i4OMA5Saaaaaaaaaaaaa8jjiKc3vi+R9l460U="
    }
    string(173) "1tbxz3gnar22=&ajmxahfjrntu=TestGUIDtest1&0q2r703dw67b=&apikey= 8acaa12c-02cb-5194-6323-098h6dc4c374&salt=1009147916&signature=i4OMA5SW824hsV5Ncia52DzQgD8jjiKc3vi%2BR9l460U%3D"
    
    cURL response (withing PHP)

    Code:
    <div style="BACKGROUND: #f8ebeb; FONT: 13px Trebuchet MS, Verdana, Helvetica, Arial; BORDER: 1px SOLID #751616; PADDING: 10px; MARGIN: 5px;"><font color="red">[Notice]: Uninitialized string offset: 0 (api/class.Controller_TicketCustomField.php:229)</font></div>
    <?xml version="1.0" encoding="UTF-8"?>
    <customfields>
    <group id="2" title="Details">
    <field id="6" title="Operating system" type="9" name="qms8sjd9cqvx" />
    </group>
    <group id="5" title="mobile details">
    <field id="9" title="Mobile Platform" type="9" name="gym3b8ulghdq" />
    <field id="17" title="Mobile Product" type="9" name="q0iuaw25uu2g" />
    </group>
    <group id="13" title="AMS-Feedback-Customer">
    <field id="37" title="Feedback type" type="6" name="zrdrdpwcm24l" />
    </group>
    <group id="3" title="internal">
    <field id="5" title="BUTR" type="2" name="1tbxz3gnar22" />
    </group>
    <group id="9" title="AMS-Feedback-Staff">
    <field id="21" title="GUID" type="1" name="ajmxahfjrntu" />
    <field id="25" title="CommunityIQ data" type="2" name="0q2r703dw67b" />
    <field id="29" title="Device log" type="11" name="o7yzrfm8blrm" />
    <field id="33" title="System dump" type="11" name="49xf3eawxo79" />
    </group>
    </customfields>
    
    The Custom Field Value does not change even from PHP API.
    I've followed the tutorial.

    PHP sample code
    Code:
    <?php
    require_once("../kyIncludes.php");
     
    print "<pre>";
    /**
    * Initialization.
    */
    kyConfig::set(new kyConfig("https://dev.support.avast.com/api", " 8acaa12c-02cb-5194-6323-098h6dc4c374", "OWNAAAbbbcbbcdsbcsbdbcbcbbcsbdcd................LWY1NGYtNDYzMzFlMTZiZDE4"));
    kyConfig::get()->setDebugEnabled(true);
     
    // get ticket
    $ticket = kyTicket::get('290709');
     
    $guid_field = 'ajmxahfjrntu';
     
    // get custom fields
    $ticketCustomFields = $ticket->getCustomFields();
     
    $custom_field = $ticket->getCustomField($guid_field);
    $custom_field->setValue('TestGUIDtest1');
     
    $ticket->updateCustomFields();
     
    ?>
    
    By the required fields, you mean following fields? Why does PHP API doesn't take care of that?


    gym3b8ulghdq
    q0iuaw25uu2g
     
  4. Tomasz Sawicki

    Tomasz Sawicki Established Member


    Yes, you must set their values (in addition to ajmxahfjrntu). PHP Library will take care of that (that is, it will throw an expection) in future release.
     
  5. Tomas Rehak

    Tomas Rehak New Member

    OK,
    so what should I do?

    Code:
    $ticket->setCustomFieldValue('gym3b8ulghdq','Android');
    $ticket->setCustomFieldValue('q0iuaw25uu2g','avast! Mobile Security');
    
    ?
     
  6. Tomasz Sawicki

    Tomasz Sawicki Established Member

    Yes, but remember about enabling User Editable flag, since these fields had it disabled according to your first post.
     
  7. Tomas Rehak

    Tomas Rehak New Member

    We are using Kayako for various purposes and for some tickets, those two ticket fields (Mobile platfrom, Mobile product) are required, however, for my purposes I don't want them to be present / have to set them when setting other Ticket custom fields.

    How can I do that?

    Thank you!
     
  8. Tomasz Sawicki

    Tomasz Sawicki Established Member

    First please check (and post here) what custom field groups are associated with department you're trying to create ticket in (it difficult to say based on API responses because of this bug).
     
  9. Tomas Rehak

    Tomas Rehak New Member

    Thank you for pointing out department side of thing.
    It turned out that access rights and department custom fields were kind of mixed. We have checked the permission and now it works.

    I think Kayako should really improve it's error reporting.

    Thank you again!
     

Share This Page