Nowadays REST API (web services) development based on RESTful architecture  is accepted across the Web as a simpler alternative to SOAP – and Web Services Description Language (WSDL)-based Web services. Key evidence of this shift is the adoption of REST by web 2.0 service providers, including Yahoo, Google, and Facebook, who have shifted their SOAP and WSDL-based web services to RESTFul API. RESTful development has become the standard way of creating a web application.

How to post a ticket using rest api?

To post a ticket using rest api we have to post the data using an http post request. That can be done by using curl, but cakephp has Http Socket which makes http post easier than the curl.

You can post ticket as a staff or a client user, the difference lies only in a single field that we post. To create ticket as staff we have to pass “staffid” and to create ticket as a client we have to pass “userid” in post.

Example :

$apiUrl = $api_url.”e=/Tickets/Ticket”;

$salt = mt_rand();

$signature = base64_encode(hash_hmac(‘sha256’,$salt,$secretKey,true));

$api_url is Rest api url and $secretKey is the secret key for rest api which can be obtained by kayako admin dash board, settings menu -> rest api sub menu.

To post ticket as a staff post data should be as below :

$post_data = array(‘subject’ => ‘Subject’,
‘fullname’ => ‘Full name’,
’email’ => ‘Mail id from which the ticket has to be posted’ ,
‘contents’ => ‘Contents of ticket’,
‘departmentid’ => ‘Department id to which the ticket has to be posted’,
‘ticketstatusid’ => ‘Status id of the ticket’,
‘ticketpriorityid’ => ‘Priority id of the ticket’,
‘tickettypeid’ => ‘Ticket type id of ticket’,
‘staffid’=>’Kayako id of staff from whose account ticket has to be created’,
‘ignoreautoresponder’=>’1’, // Should be 1 if autogenerated mail should no be sent to user, 0 if mail has to be sent
‘apikey’ => $apiUrl,
‘salt’ => $salt,
‘signature’ => $signature);

To post ticket as a user post data should be as below :

$post_data = array(‘subject’ => ‘Subject’,
‘fullname’ => ‘Full name’,
’email’ => ‘Mail id from which the ticket has to be posted’ ,
‘contents’ => ‘Contents of ticket’,
‘departmentid’ => ‘Department id to which the ticket has to be posted’,
‘ticketstatusid’ => ‘Status id of the ticket’,
‘ticketpriorityid’ => ‘Priority id of the ticket’,
‘tickettypeid’ => ‘Ticket type id of ticket’,To our surprise, CakePHP’s built-in authentication with ACL was the slowest part of the application, due to joining in the aro/aco/users tables. We also discovered one of our applications was not caching properly, requesting object schemas on each call.
userid’=>’Kayako id of user from whose account ticket has to be created’,
‘ignoreautoresponder’=>’1’, // Should be 1 if autogenerated mail should no be sent to user, 0 if mail has to be sent
‘apikey’ => $apiUrl,
‘salt’ => $salt,
‘signature’ => $signature);

Please note : None of the post data data has to be empty.

Finally coming to posting the data :

Using curl :

$post_data = http_build_query($post_data, ”, ‘&’);
$curl = curl_init($apiUrl);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_URL, $apiUrl);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
$response = curl_exec($curl);
curl_close($curl);

$response will have the kayako response of the ticket posted. It will be an API response which will have all the details of ticket.

Using HTTP Socket of cakephp :

$post_data = http_build_query($post_data, ”, ‘&’);

App::import(‘Core’, ‘HttpSocket’);
$HttpSocket = new HttpSocket();
$results = $HttpSocket->post($apiUrl, $post_data);

$results will have the kayako response of the ticket posted. It will be an API response which will have all the details of ticket.

This completes the creation of ticket in kayako using restapi.

Read more posts here:-

DevOps Predictions 2017

How to Choose the Best Outsourced Web Hosting Technical Support Provider?

How to migrate your legacy apps on the cloud with AWS

For highly competitive pricing and excellent web hosting technical support services contact InstaCarma today!

 


Shares
Contact Us On WhatsApp