Skip to main content

OSticket REST API Calls

Shenzhen, China

Generate an API Key

Access to the HTTP API is restricted to valid API keys. An X-API-Key HTTP header must be sent to indicate which API key is to be used with the request. The API key must match the remote IP of the connected HTTP client. The remote IP is checked as usual. If the osTicket server is sitting behind a reverse proxy, the original IP of the client will be retrieved from the X-Forwarded-For header, if provided by your proxy.

Admin Panel / Manage / API / Add new API key

OSticket REST API Calls

OSticket REST API Calls

GET Request

Example:

X-API-Key: BA00B76BAA30F62E1940B46CC1C3C73C

Make an empty GET request:

curl -d "{}" -H "X-API-Key: BA00B76BAA30F62E1940B46CC1C3C73C" "https://support.you.tld/api/tickets.json"
No errors

POST Request

Run Cron Job

curl -X POST -H "X-API-Key: BA00B76BAA30F62E1940B46CC1C3C73C" "https://support.you.tld/api/tasks/cron" 
API key not authorized

OSticket REST API Calls

curl -X POST -H "X-API-Key: BA00B76BAA30F62E1940B46CC1C3C73C" "https://support.you.tld/api/tasks/cron"
Completed

Post a Ticket

curl -H "X-API-KEY: BA00B76BAA30F62E1940B46CC1C3C73C" -d '{"alert": true, "autorespond": true, "source": "API", "topicId": 1, "name": "User Name", "email": "user@noemail.com", "subject": "Testing API", "message": "data:text/html,<h2>Good day!</h2><br/><p>My device is broken.<b>AGAIN!</b></p><p>I did not change anything!</p><br/><p>But after the last firmware update I am no longer able to start it.</p><p><b>Are you testing your firmware AT ALL before releasing it?????</b></p>", "attachments": [{"filename.txt": "data:text/plain;charset=utf-8,content of attachment"}]}' https://support.you.tld/api/tickets.json
602343

OSticket REST API Calls

UTF-8 Encoding:

curl -H "X-API-KEY: 3DE660A1A575EBD6D17F4517B5378C90" -v -d '{"alert": true, "autorespond": true, "source": "API", "topicId": 1, "name": "Very Angry User", "email": "me@noemail.com", "phone": "123456768", "subject": "Tästing sí API", "message": "data:text/html;charset=utf-8,<h2>Góod däy!</h2><br/><p>My device is bröken.<b>ÄGAIN!</b></p><p>I did not chänge änything!</p><br/><p>Büt äfter the last firmware üpdate I am nö lönger äble to stärt it.</p><p><b>Äre yóu testing yöür firmwäre AT ALL beföre releäsing it?????</b></p>", "attachments": [{"feilenäm.txt": "data:text/plain;charset=utf-8,cöntänt üf attächmänt"}]}' https://time.instar.com/api/tickets.json

Use Python to Post Tickets

import requests

url = "https://support.you.tld/api/tickets.json"
key = "BA00B76BAA30F62E1940B46CC1C3C73C"

headers = {
        "Accept":"application/json",
        "X-API-KEY":key
    }

data = {"name":"Angry User",
"email":"api@osticket.com",
"phone":"3185558634X123",
"subject": "Testing API",
"ip": "123.211.233.122",
"message":"data:text/html,<h2>Good day!</h2><br/><p>My device is broken.<b>AGAIN!</b></p><p>I did not change anything!</p><br/><p>But after the last firmware update I am no longer able to start it.</p><p><b>Are you testing your firmware AT ALL before releasing it?????</b></p>",
"attachments": [{"attachment.txt": "data:text/plain;charset=utf-8,content of attachment"}],
"topicId": 1,
"autorepsond":True,
"alert": True,
"source": "API"}


def createTicket():

    r = requests.post(url=url,json=data,headers=headers)

    print('INFO :: Request Status Code: ', r.status_code)

    if (r.status_code < 200 or r.status_code >= 300):
        return False

    print('INFO :: Ticket Number: ', r.json())
    return True


createTicket()

Run the script on localhost:

python ./main.py
INFO :: Request Status Code:  201
INFO :: Ticket Number:  208979

OSticket REST API Calls