I feel that there is very little documentation and examples around of how to do this, and it bugged me for more than 10 minutes, so I thought I’d share my findings.
The documentation can currently be found here: https://github.com/osTicket/osTicket-1.7/blob/develop/setup/doc/api.md and here: https://github.com/osTicket/osTicket-1.7/blob/develop/setup/doc/api/tickets.md
A sample script can be found here: https://github.com/osTicket/osTicket-1.7/blob/develop/setup/scripts/rcron.php (which is what I based the following example off).
But I like to be somewhat lazy and copy and paste a script, test to see it works and then go about tweaking it.
URL to api/tickets.json e.g http://yourdomain.com/support/api/tickets.json
# key => API's Key (see admin panel on how to generate a key)
$config = array(
'key'=>'[long api key goes here]'
function_exists('curl_version') or die('CURL support required');
#Sample data for the ticket
# See https://github.com/osTicket/osTicket-1.7/blob/develop/setup/doc/api/tickets.md for full list of variables and options that you can pass.
$data = array("alert" => "true",
"autorespond" => "true",
"source" => "API",
"name" => "Angry User",
"email" => "[email protected]",
"subject" => "Testing API 3",
"message" => "MESSAGE HERE"
#Convert the above array into json to POST to the API with curl below.
$data_string = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $config['url']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_USERAGENT, 'osTicket API Client v1.7');
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Expect:', 'X-API-Key: '.$config['key']));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
if(preg_match('/HTTP\/.* ([0-9]+) .*/', $result, $status) && $status == 200)
Then follow your hosts instructions for adding a Cron Job.
Mine looks something like this: