Native PHP Class
Note: Because Kayako relies on global variables, the below code <b>cannot be used inside a function or class</b>. As such, its use is extremely limited - you will be much better off using the SOAP interface.
<?php
$username = 'username'; //Username for Integration API as defined in /lib/config.php
$password = 'password'; //Password for Integration API as defined in /lib/config.php
require './helpdesk/integrationapi/lib/api.class.php';
$params = array($username,
$password,
//Email address of the Kayako user to get tickets for
'someone@example.com',
//Number of tickets to show per page
5,
//Page number. 1 displays tickets 1-5; 2 displays 6-10; etc.
1,
//Column to sort by (lastactivity, lastreplier, ticketstatusid,
// priorityid, departmentid)
'lastactivity',
//TRUE to sort in ascending order, FALSE to sort in descending order
false
);
$result = call_user_func_array(array('CBS_KayakoAPI','getSubmittedTickets'), $params);
if ($result < 0) {
//The API threw an error
switch ($result->detail) {
case -1: "The API username and password that you used are not valid"; break;
case -2: "An invalid email address was supplied"; break;
case -3: "A non-existent user was specified"; break;
case -4: "The number per page is not numeric"; break;
case -5: "The page number is not numeric"; break;
case -6: "An invalid 'sort-by' field was specified (must be one of: lastactivity, lastreplier, ticketstatusid, priorityid, departmentid)"; break;
case -7: "An incorrect password type was specified (must be 1 or 0)"; break;
case -8: "An invalid department ID was specified"; break;
case -9: "An invalid priority ID was specified"; break;
case -10: "Required ticket information was missing"; break;
case -11: "Required comment information was missing"; break;
case -12: "The reply specified was empty"; break;
case -13: "The specified ticket could not be found"; break;
case -14: "The requested ticket is not owned by the specified user"; break;
case -15: "The new email address specified is already in the database"; break;
case -16: "Both status and priority were empty"; break;
case -17: "A non-existent status was specified"; break;
case -18: "A non-existent priority was specified"; break;
case -19: "The specified attachment could not be found"; break;
case -20: "The specified category could not be found"; break;
case -21: "The specified article could not be found"; break;
case -22: "The API was unable to fetch the submitted attachment"; break;
case -23: "A non-existent custom field group was specified"; break;
case -24: "A non-existent custom field was specified"; break;
case -25: "An empty value was specified for a custom field marked as \"required\""; break;
case -26: "An incorrect typeid (ticket ID) value was specified"; break;
default:
$msg = 'Unknown Error';
}
trigger_error("Kayako API Error: $msg", E_USER_ERROR);
} else {
//Our request was successful. $result now contains an array of submitted tickets
?>
<h1>Successful Request</h1>
<h2>Submitted Tickets:</h2>
<pre><?php print_r($result); ?></pre>
<?php
}
?>SOAP Interface
<?php
$url = 'http://www.yourdomain.com/helpdesk/integrationapi/index.php?wsdl'; //URL to Integration API
$username = 'username'; //Username for Integration API as defined in /lib/config.php
$password = 'password'; //Password for Integration API as defined in /lib/config.php
require './nusoap/nusoap.php';
$nuSoapClient = new nusoap_client($url, 'wsdl');
function call($method, $params) {
global $nuSoapClient;
$result = $nuSoapClient->call($method, $params);
if ($nuSoapClient->fault) {
//The API threw an error
switch ($result['detail']) {
case -1: $msg = "The API username and password that you used are not valid"; break;
case -2: $msg = "An invalid email address was supplied"; break;
case -3: $msg = "A non-existent user was specified"; break;
case -4: $msg = "The number per page is not numeric"; break;
case -5: $msg = "The page number is not numeric"; break;
case -6: $msg = "An invalid 'sort-by' field was specified (must be one of: lastactivity, lastreplier, ticketstatusid, priorityid, departmentid)"; break;
case -7: $msg = "An incorrect password type was specified (must be 1 or 0)"; break;
case -8: $msg = "An invalid department ID was specified"; break;
case -9: $msg = "An invalid priority ID was specified"; break;
case -10: $msg = "Required ticket information was missing"; break;
case -11: $msg = "Required comment information was missing"; break;
case -12: $msg = "The reply specified was empty"; break;
case -13: $msg = "The specified ticket could not be found"; break;
case -14: $msg = "The requested ticket is not owned by the specified user"; break;
case -15: $msg = "The new email address specified is already in the database"; break;
case -16: $msg = "Both status and priority were empty"; break;
case -17: $msg = "A non-existent status was specified"; break;
case -18: $msg = "A non-existent priority was specified"; break;
case -19: $msg = "The specified attachment could not be found"; break;
case -20: $msg = "The specified category could not be found"; break;
case -21: $msg = "The specified article could not be found"; break;
case -22: $msg = "The API was unable to fetch the submitted attachment"; break;
case -23: $msg = "A non-existent custom field group was specified"; break;
case -24: $msg = "A non-existent custom field was specified"; break;
case -25: $msg = "An empty value was specified for a custom field marked as \"required\""; break;
case -26: $msg = "An incorrect typeid (ticket ID) value was specified"; break;
default:
$msg = 'Unknown Error';
}
die('<div style="color:red;background-color:#faa;"><h1>Kayako API Error</h1><p>'.htmlspecialchars($msg).'</p></div>');
} elseif ($error = $nuSoapClient->getError()) {
//The SOAP client was unable to successfully communicate with the remote Kayako API
die('<div style=\"color:red;background-color:#faa;\"><h1>SOAP Error</h1><pre>' . htmlspecialchars(print_r($error, true)) . '</pre><hr /><pre>' . htmlspecialchars(print_r($nuSoapClient->response,true)) . '</pre></div>');
}
return $result;
}
$params = array('user' => $username,
'password' => $password,
//Email address of the Kayako user to get tickets for
'email' => 'someone@example.com',
//Number of tickets to show per page
'numPerPage' => 5,
//Page number. 1 displays tickets 1-5; 2 displays 6-10; etc.
'page' => 1,
//Column to sort by (lastactivity, lastreplier, ticketstatusid,
// priorityid, departmentid)
'sortBy' => 'lastactivity',
//TRUE to sort in ascending order, FALSE to sort in descending order
'orderAsc' => false
);
$result = call('getSubmittedTickets', $params);
//Our request was successful. $result now contains an array of submitted tickets
?>
<h1>Successful Request</h1>
<h2>Submitted Tickets:</h2>
<pre><?php print_r($result); ?></pre>
This post has been edited by Andrew Gillard: 07 September 2009 - 11:05 AM
Reason for edit: Fixing IPB 2 code
Sign In »
Register Now!
Help
This topic is locked


Back to top








