ticket insertion in api with custom field

19 views
Skip to first unread message

Vaibhav shukla

unread,
Aug 19, 2019, 10:57:01 AM8/19/19
to SherpaDesk API

We are having two custom fields created thru admin panel in sherpadesk.From front end add ticket form we are adding custom fields and inserting them thru api.Custom field not showing values in attached screenshot.

Check our code:

if (isset($_POST['classes']) && $_POST['classes']!='') {

$class=$_POST['classes'];

}

if (isset($_POST['child_classes']) && $_POST['child_classes']!='') { //If child class selected,set class as child_class_id

$child_class_id=$_POST['child_classes'];

$class=$child_class_id;

}else{

$child_class_id='';

}

if (isset($_POST['child_child_classes']) && $_POST['child_child_classes']!='') { //If child child class selected,set class as child_child_class_id

$child_child_class_id=$_POST['child_child_classes'];

$class=$child_child_class_id;

}else{

$child_child_class_id='';

}

$data_array=array(

"status" => "open",

"subject" => $subject,

"initial_post" => $initial_post,

"class_id" => $class,

"account_id" => $account_id,

"location_id" => $location_id,

"user_id" => $user_id,

"tech_id" => $technicians,

"ctl00$PageBody$ctl02"=> $tc_ticket_no,//customfield 1

"ctl00$PageBody$ctl04"=> $tp_name,////customfield 2

);

$URL='https://'.ORG_KEY.'-'.INSTANCE_KEY.':'.API_KEY.'@api.sherpadesk.com/tickets/';//API URL

$make_call = callAPI('POST', $URL ,json_encode($data_array));//Function to call api url using CURL and return json response

$response = json_decode($make_call, true);//Convert json response into php array

if (!empty($response)) {

header('location:success.php');

} else {

echo "

Sorry! Ticket not added.

";

}


 // CURL API call

    function callAPI($method, $url, $data){

   $curl = curl_init();

   switch ($method){

      case "POST":

         curl_setopt($curl, CURLOPT_POST, 1);

         if ($data)

            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

         break;

      case "PUT":

         curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");

         if ($data)

            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

         break;

      default:

         if ($data)

            $url = sprintf("%s?%s", $url, http_build_query($data));

   }

   // OPTIONS:

   curl_setopt($curl, CURLOPT_URL, $url);

   curl_setopt($curl, CURLOPT_HTTPHEADER, array('APIKEY:'.API_KEY,'Content-Type: application/json'));

   curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

   curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

   // EXECUTE:

   $result = curl_exec($curl);

   if(!$result){die("Connection Failure");}

   curl_close($curl);

   return $result;

}


Capture.PNG

Eugene Tolmachev

unread,
Aug 20, 2019, 2:03:21 AM8/20/19
to Vaibhav shukla, SherpaDesk API, zwoja4...@app.sherpadesk.com

Hi,


see update ticket and

https://github.com/sherpadesk/api/wiki#update-ticket-custom-fields



you need to create xml string


<root><field id="1"><caption>Have You Rebooted?</caption><value>Yes</value></field></root>


where id - is custom field id, and value


see example in mobile site (this is good examples of using api)

 






От: Vaibhav shukla <vaibhav1...@gmail.com>
Отправлено: 20 августа 2019 г. 7:36
Кому: Eugene Tolmachev <eug...@micajah.com>
Тема: ticket insertion in api with custom field
 
How to insert custom fields into sherpadesk api so that their values are visible in screenshot as shown.

Check ticket 16704.

Eugene Tolmachev

unread,
Aug 20, 2019, 2:11:07 AM8/20/19
to Vaibhav shukla, SherpaDesk API


key returns in response of POST /tickets
examine response


От: Vaibhav shukla <vaibhav1...@gmail.com>
Отправлено: 20 августа 2019 г. 9:09
Кому: Eugene Tolmachev <eug...@micajah.com>
Тема: Re: ticket insertion in api with custom field
 
How to get ticket key of recently inserted ticket?

--
You received this message because you are subscribed to the Google Groups "SherpaDesk API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sherpadesk-ap...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sherpadesk-api/BYAPR04MB5864C2858A7A10E3440EF8BDC9AB0%40BYAPR04MB5864.namprd04.prod.outlook.com.
Reply all
Reply to author
Forward
0 new messages