Markdown Support: API Integration
Markdown via API: format field in requests, auto-detection with pattern weights, interplay with the API Endpoints plugin and notes on emails for API-created tickets.
Markdown Support: API Integration
The plugin has no ticket API of its own. When a thread entry is created, it sets the format if the request carries one, and it can optionally detect Markdown syntax automatically.
Format in the request
The signal handler threadentry.created determines the format in this order:
- The form field
formatin$_POST. - With
Content-Type: application/json, the fieldformatin the JSON body.
Valid values are markdown, html and text (case-insensitive). Any other value becomes html. The plugin then writes the determined format to the format column of the thread entry.
{
"name": "Max Mustermann",
"email": "max@example.com",
"subject": "Ticket with Markdown",
"message": "## Problem\n\nThe server does **not** respond.",
"format": "markdown"
}
The plugin reads the text for line break restoration and auto-detection from the fields response, note, message and body (the first non-empty field wins).
osTicket partly strips line breaks when saving. The plugin restores them if the text in
$_POSTcontains line breaks and the saved entry has none.
Auto-detection
With the option Auto-Convert Markdown Syntax, the plugin stores entries as Markdown when the request carries no format in $_POST and the text contains Markdown syntax.
Each pattern counts once, no matter how often it occurs:
| Pattern | Points | Example |
|---|---|---|
| Code block | 20 | ```code``` |
| Heading | 15 | # Title |
| Link | 15 | [text](url) |
| Bullet list | 12 | - item or * item |
| Numbered list | 12 | 1. item |
| Bold | 10 | **bold** |
| Quote | 10 | > quote |
| Italic | 8 | *italic* |
| Inline code | 5 | `code` |
| Horizontal rule | 5 | --- |
The threshold is fixed at 5. A single detected pattern is therefore enough to store the entry as Markdown.
The detection is very sensitive: even a line like
- itemor a word in*asterisks*counts as Markdown. For API calls, rather send theformatfield explicitly.
Interplay with API Endpoints
The API Endpoints plugin accepts format on POST /tickets and validates the value. It merges the JSON body into $_POST before the ticket is created. This is how the signal handler of this plugin finds the format.
- For notes through the update function of API Endpoints, the field
noteFormatapplies. If it is missing, API Endpoints usesmarkdown. - The option Require Markdown Plugin of API Endpoints (default: off) rejects
format=markdownwith an error if Markdown Support is not active. API Endpoints recognizes the plugin by the existence of the classMarkdownThreadEntryBody. The class only exists when Markdown Support is activated and Parsedown has been loaded. - Use the value
markdownin requests. Markdown Support does not know other spellings that API Endpoints accepts.
Emails for API tickets
The plugin converts Markdown to HTML in advance for outgoing emails only for requests with format=markdown in $_POST (see Technical details). This conversion runs when osTicket starts and does not yet see the JSON body of an API request. For API tickets the plugin therefore only sets the format of the stored entry.