A request to the Kayako REST API is simply an HTTP request with the URL set to the path of the helpdesk app (such as Base), the controller (like User), and the parameters containing the payload of the request. One request that you can do using Kayako REST API is retrieving ticket posts.
This article provides instructions on how to generate the API query syntax to retrieve ticket posts in Kayako Classic.
Before you begin constructing your API query syntax, ensure that the helpdesk API is active.
Important: Use the Kayako's REST API article as a reference in constructing your query. Use the API key and the secret key to generate a signature.
Generating a Signature
Use the PHP code snippet below:
<?php $apiKey = "apikey"; $secretKey = "secretkey"; // Generates a random string of ten digits $salt = mt_rand(); // Computes the signature by hashing the salt with the secret key as the key $signature = hash_hmac('sha256', $salt, $secretKey, true); // base64 encode... $encodedSignature = base64_encode($signature); // urlencode... $encodedSignature = urlencode($encodedSignature); echo "Voila! A signature: " . $encodedSignature; ?>
Note: Using PHP is highly recommended. If you are unsure of your code, please run the code first using a PHP emulator like PHPTester.
- Go to Admin CP > REST API > API Information and copy your REST API key and secret key information:
Replace the values of the
$secretKeyvariables in the code snippet with the REST API and secret key information you have obtained.
Note: Ensure that you paste the key values between the quotation marks.
In this example, we are going to use a static 10-digit number as the value of salt. It is less secure but makes the process more straightforward. You can also generate a random string for the value of salt using PHPTester. After determining your 10-digit salt, replace
mt_rand()with the salt code:
$salt = 1234567890;
- Copy the code snippet and go to PHPTester. Paste the code on the first field and click the Click to test your PHP code button to generate a signature key:
Constructing the Query Syntax
Using the generated API signature above, construct the following query syntax based on the REST TicketPost methods and principles:
For All the Ticket Posts on a Given Ticket ID:
GET http://<YourKayakoDomain>/api/index.php?e=/Tickets/TicketPost/ListAll//[add_sequential_ticket_ID_here]/&apikey=[your _api_key]&salt=[10_digit_salt]&signature=[signature]
For a Single Ticket Post on a Given Ticket ID:
GET http://<YourKayakoDomain>/api/index.php?e=/Tickets/TicketPost/[add_sequential_ticket_ID_here]/[add_ticket_post_ID_here]/&apikey=[your _api_key]&salt=[10_digit_salt]&signature=[signature]
<Kayako domain>with your Kayako Classic domain.
Replace the API Key, salt, and Signature with the information you have gathered from the steps above. Remember to remove the [ ] brackets when pasting the API Key, salt, and Signature.
Use Postman, or you may remove
GETfrom the query and copy the URL directly to the browser's address bar to receive the payload output. This will return ticket posts in XML format.