Markus Michalski FAQ

API Endpoints: Technical Details

Technical details of the osTicket API Endpoints plugin: signal routes, standalone endpoint files, request flow, directory structure, database columns, security and tests.

Deutsche Version

Back to overview

API Endpoints: Technical Details

This documentation always describes the latest published version.

Architecture

The plugin uses two paths into osTicket's API:

Signal Handler Purpose
api onApiRequest() Registers the two routes for ticket creation and update
graph TD
    A["Client request"] --> B["POST /api/tickets.json or PATCH /api/tickets/:number.json"]
    A --> C["Endpoint files in /api/, for example tickets-get.php"]
    B --> D["Signal api, onApiRequest"]
    D --> E["ExtendedTicketApiController"]
    C --> F["ApiBootstrap"]
    F --> E
    F --> G["SubticketApiController"]
    E --> H["Services and osTicket core"]
    G --> H
    H --> I["JSON, XML or plain text response"]

Request Flow of a Standalone Endpoint

sequenceDiagram
    participant C as Client
    participant E as Endpoint file
    participant B as ApiBootstrap
    participant K as Controller
    participant P as PermissionChecker
    participant S as Service

    C->>E: GET /api/tickets-get.php/781258.json
    E->>B: parse path and check method
    E->>K: getTicket(number)
    K->>P: require can_read_tickets
    P-->>K: allowed or 401
    K->>S: TicketService.getTicket
    S-->>K: ticket data
    K-->>B: array
    B-->>C: JSON or XML

ApiBootstrap is the shared base of all endpoint files: it parses the path with a regular expression, checks the HTTP method (405), parses the JSON body and sends successful responses and errors. Exceptions carry the HTTP status code.

Layers

Part File Task
Controllers controllers/ExtendedTicketApiController.php Extends osTicket's TicketApiController: creation, update, API key check
controllers/SubticketApiController.php Subticket operations, optional department check, plugin check
Services lib/Services/TicketService.php Retrieval, search, statistics, statuses, deletion
lib/Services/TicketValidatorService.php Validation and name lookup of format, department, topic, status, SLA, staff, parent, due date
lib/Services/PermissionChecker.php Reads the permission columns of the API key
lib/Services/AttachmentService.php Attachment download with a check against the attachment table
Enums lib/Enums/ Permission, MessageFormat, SortField
Helpers lib/ApiBootstrap.php, lib/XmlHelper.php Request handling and XML output

Directory Structure

api-endpoints/
β”œβ”€β”€ api/                          # Endpoint files, copied to /api/
β”‚   β”œβ”€β”€ tickets-get.php
β”‚   β”œβ”€β”€ tickets-update.php
β”‚   β”œβ”€β”€ tickets-delete.php
β”‚   β”œβ”€β”€ tickets-search.php
β”‚   β”œβ”€β”€ tickets-stats.php
β”‚   β”œβ”€β”€ tickets-statuses.php
β”‚   β”œβ”€β”€ tickets-attachment-download.php
β”‚   └── tickets-subtickets-{parent,list,create,unlink}.php
β”œβ”€β”€ assets/
β”‚   └── admin-apikey-extension.js # Admin script, not loaded by the plugin code
β”œβ”€β”€ controllers/
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ ApiBootstrap.php
β”‚   β”œβ”€β”€ XmlHelper.php
β”‚   β”œβ”€β”€ Enums/
β”‚   └── Services/
β”œβ”€β”€ tests/                        # PHPUnit tests (Unit, Integration)
β”œβ”€β”€ docs/
β”œβ”€β”€ class.ApiEndpointsPlugin.php  # Plugin class ApiEndpointsPlugin
β”œβ”€β”€ config.php                    # Config class ApiEndpointsConfig
β”œβ”€β”€ plugin.php                    # Plugin manifest
β”œβ”€β”€ htaccess.template             # Rewrite rules for /api/.htaccess
└── openapi.yaml                  # OpenAPI description

Database

The plugin adds six columns of type TINYINT(1) UNSIGNED NOT NULL DEFAULT 0 to osTicket's API key table: can_update_tickets, can_read_tickets, can_search_tickets, can_delete_tickets, can_read_stats and can_manage_subtickets. The columns are created if they are missing, existing data is not touched. Disabling or removing the plugin does not drop them.

Behaviour Worth Knowing

Security

Tests

The tests run with PHPUnit:

composer install
composer test              # all tests
composer test:unit         # unit tests only
composer test:integration  # integration tests only
composer test:coverage     # HTML coverage report

OpenAPI

The repository contains openapi.yaml with an OpenAPI description of the endpoints. This documentation is the reference where the two differ.