Adam Laycock

Network Manager, Developer & Blogger

OSTicket API Proxy

Over at Ed-IT Solutions we use OSTicket for our help desk. We like it and it does its job very well. Early in the development of our support app, the question was asked, “Can users open tickets from inside the app?”. Yes! They can, but some trickery is going to be needed to get it working. OSTicket has this odd restriction that every API key needs to be assigned to one IP and one IP only. Hence the need for an OSTicket API Proxy. Our app is on hundreds of computers on various ISPs, on laptops that travel all over the place. A single IP does not exist.

The answer is to proxy the API requests through another API.


Create an API key on your OSTicket for the IP of your web server. Upload this file to your web server.

2$config = array(
3 'url'=>'https:/',
4 'key'=> $_POST['apiKey']
7$data = array(
8 'name' => $_POST['name'],
9 'email' => $_POST['email'],
10 'subject' => $_POST['subject'],
11 'message' => $_POST['message'],
12 'ip' => $_SERVER['REMOTE_ADDR'],
13 'topicId' => '19' // Change to the id of your default topic.
16$options = array(
17 'http' => array(
18 'header' => "X_API_Key: ".$config['key'],
19 'method' => 'POST',
20 'content' => json_encode($data)
21 )
23$context = stream_context_create($options);
24$result = file_get_contents($config['url'], false, $context);
25if ($result === FALSE) { die("FAILED"); }
Language php

The topic ID needs changing to the ID of one of your topics. We have everything come into a generic support topic which we categorize after we read it.

Using OSTicket API Proxy

To create a ticket send a POST request to the address of the API file from above. Your post data need to contain:

  • apiKey – The osTicket API Key, this means you still need the API key in each client.
  • name – The name of the user
  • email – The user’s email address
  • subject – The tickets subject
  • message – The tickets message

I specifically wanted my clients to require the API Key, this stops an attacker finding your API Proxies address and sending thousands of tickets through it.

The API proxy returns the response from OSTicket or Failed if there was a problem making the request to OSTicket.

We have been using this quite successfully for a couple of weeks now and I am pretty happy with it. It would be possible to move the topic ID into your post data if you want that selection to be made by the user in your app.

Adam Laycock

Adam Laycock

Network Manager, Developer & Blogger

All content is my own unless otherwise stated.

My content is licensed under the CC-BY-NC-SA 4.0 license