# API reference

> **In short.** Base address `https://desk.juncodesk.app/v1/games/<public key>`. Say who the user is on every call
> with `Authorization: Bearer <signed token>` or `X-Junco-Player: <random id>`. JSON in and out;
> files by `multipart/form-data`. Errors are `{"error": "..."}` with words you can show the user.
> A user only ever sees their own tickets. Machine-readable: `https://desk.juncodesk.app/openapi.json` (OpenAPI 3.1).

This is the API Junco's own widget uses. Use it to build your own support form in a game engine,
a native app or a server. There's no API key: the public key names the product, and the user is
identified as below.

## Who the user is

Every request carries one of:

- **A signed token**, for users who sign in: `Authorization: Bearer <token>`, a JWT your server
  signs with the product's Ed25519 key. See [Signed user tokens](/docs/user-tokens).
- **A random id**, for everyone else: `X-Junco-Player: <id>`, 32 to 128 characters from
  `A-Z a-z 0-9 _ -`, made once per install or browser and kept. Losing it loses access to that
  user's old tickets. Allowed only while the product's **Without an account** setting is on.

If both are sent, the token is used.

## Browsers and CORS

Calls from a web page carry an `Origin` header, which must be one of the product's web addresses
in Junco (or Junco's own hosted page while that's on); otherwise 403. Junco answers preflight
`OPTIONS` requests for `GET`, `POST` and `DELETE` with the headers `Authorization`,
`Content-Type` and `X-Junco-Player`. Native apps, engines and servers send no `Origin` and need
nothing listed. Don't send cookies; Junco doesn't use them here.

## Endpoints

| Method and path | Does | Success |
|---|---|---|
| `POST /tickets` | Raise a ticket | `201` ticket with messages |
| `GET /tickets` | The user's tickets | `200` `{"tickets": [...]}` |
| `GET /tickets/{number}` | One ticket and its messages; marks it read | `200` ticket with messages |
| `POST /tickets/{number}/messages` | The user replies; reopens a closed ticket | `201` ticket with messages |
| `GET /unread` | How many tickets have replies the user hasn't read | `200` `{"count": 2}` |
| `DELETE /me` | Delete everything this user has sent | `200` `{"deleted": {"tickets": 3, "files": 1}}` |
| `POST https://desk.juncodesk.app/v1/releases` | Tell users their fixes are live (deploy scripts) | `201` `{"released": 4, "version": "1.4.2"}` |

### Raise a ticket: `POST /tickets`

JSON body:

| Field | Type | Required | Notes |
|---|---|---|---|
| `type` | `"bug"`, `"idea"` or `"help"` | yes | What the user chose. |
| `text` | string | yes | What they wrote, 1 to 5,000 characters. |
| `title` | string | no | Up to 140 characters. Without one, Junco makes one from the first line, and the AI may improve it. |
| `handle` | string | no | The user's display name for your team, up to 40 characters. A token's `name` wins. |
| `context` | object | no | Anything useful: version, screen, device, settings. Up to 16 KB as JSON. No personal details. |

```sh
curl -s -X POST https://desk.juncodesk.app/v1/games/jk_YOUR_KEY/tickets \
  -H "Content-Type: application/json" \
  -H "X-Junco-Player: 7kQ2mVx9pL4rT8wN3bY6cH1jF5sD0aZe" \
  -d '{"type":"bug","text":"The map is blank after I dock at Ilse Strand.","context":{"version":"0.9.2","screen":"Map","device":"iPhone 15, Safari"}}'
```

```json
{
  "number": 42,
  "type": "bug",
  "status": "ai_handling",
  "stage": "ai_handling",
  "title": "The map is blank after I dock at Ilse Strand.",
  "createdAt": "2026-11-24T21:14:03.120Z",
  "lastMessageAt": "2026-11-24T21:14:03.120Z",
  "unread": false,
  "messages": [
    { "id": "5f0c…", "from": "player", "text": "The map is blank after I dock at Ilse Strand.", "at": "2026-11-24T21:14:03.120Z" }
  ],
  "aiWorking": true
}
```

`aiWorking: true` means the AI is writing a reply: fetch the ticket again every couple of seconds
until it's false. A ticket's `number` is per product, and is how you refer to it afterwards.

**With files**, send `multipart/form-data`: a `ticket` field holding the JSON above as text, plus
up to three files:

| Field | Accepts | Up to |
|---|---|---|
| `screenshot` | PNG, JPEG or WebP (checked from the bytes) | 2 MB |
| `save` | Anything; kept as a download | 1 MB |
| `log` | UTF-8 text, no NUL bytes | 512 KB |

At most 4 MB a request. Any other field name is refused.

```sh
curl -s -X POST https://desk.juncodesk.app/v1/games/jk_YOUR_KEY/tickets \
  -H "X-Junco-Player: $ID" \
  -F 'ticket={"type":"bug","text":"Crashed when I opened the hangar"}' \
  -F 'screenshot=@crash.jpg' -F 'log=@game.log'
```

### List: `GET /tickets`

The user's tickets for this product, newest activity first, without messages:

```json
{ "tickets": [ { "number": 42, "type": "bug", "status": "resolved", "stage": "released", "title": "Blank map after docking", "createdAt": "…", "lastMessageAt": "…", "unread": true } ] }
```

### One ticket: `GET /tickets/{number}`

The same as the answer to raising a ticket, with every message the user can see (never your
team's internal notes). Marks the ticket read. Another user's ticket number answers 404.

Messages have `from`: `"player"` (the user), `"ai"` or `"staff"` (your team; never a name), `text`
(plain text) and `at` (ISO 8601).

### Reply: `POST /tickets/{number}/messages`

Body `{"text": "Still blank after the update"}` (1 to 5,000 characters). Answers `201` with the
ticket. Reopens a resolved or released ticket; the AI answers if it's handling the ticket, and
your team is alerted if it's with them.

### Unread: `GET /unread`

`{"count": 2}`: tickets with replies the user hasn't opened. For a badge on your Support button.

### Delete everything: `DELETE /me`

Deletes every ticket, message and file this user has sent to this product. Can't be undone. Offer
it in your settings with a confirm, as the widget does.

## Statuses

Each ticket has `stage`, the full status, and `status`, one of the first four for older clients:

| `stage` | `status` | Tell the user |
|---|---|---|
| `ai_handling` | `ai_handling` | Being looked at |
| `needs_you` | `needs_you` | With the team |
| `waiting_on_player` | `waiting_on_player` | Waiting for you: reply when you can |
| `in_progress` | `needs_you` | Being worked on |
| `awaiting_release` | `needs_you` | Fixed: coming in the next update |
| `resolved` | `resolved` | Resolved: reply if it's still a problem |
| `released` | `resolved` | Fixed and live |

Read `stage` and fall back to `status`; treat a value you don't know as "With the team".

## Releases: `POST /v1/releases`

From a deploy script, after a new version is live. Every ticket waiting for a release (its GitHub
issue was closed as completed) moves to **Released**, and each user is told in their thread.

```sh
curl -s -X POST https://desk.juncodesk.app/v1/releases \
  -H "Authorization: Bearer $JUNCO_RELEASE_KEY" \
  -H "Content-Type: application/json" \
  -d '{"version": "1.4.2"}'
```

| Field | Notes |
|---|---|
| `version` | Optional, up to 40 characters of letters, digits, `.`, `_`, `+`, `-` and spaces. Shown to users. |
| `issues` | Optional: only the fixes from these GitHub issue numbers, e.g. `[12, 15]`. Up to 200. |

The release key (`jr_...`) is made on the desk's **Releases** page and names the product. It's a
secret: keep it in your CI's secrets. With GitHub connected you may not need this at all:
publishing a GitHub release does the same ([GitHub and releases](/docs/github)).

## Errors

Every error is JSON: `{"error": "..."}`. The words are safe to show users.

| Status | When |
|---|---|
| `400` | A field is missing or wrong (the message names it, e.g. `text: Too small`), unexpected form field, bad JSON. |
| `401` | `Missing player`, `This game needs a player token`, `Player token isn't valid`, `This game doesn't use player tokens`, or a bad random id. |
| `403` | `This page isn't allowed to use this game's support`: a browser `Origin` that isn't listed. |
| `404` | `Unknown game` (the public key), `No such ticket`. |
| `413` | `That's too big to send`, `Game context is too big`, `The screenshot is too big`. |
| `415` | `Send JSON or multipart form data`, `The screenshot isn't a file type Junco accepts`. |
| `429` | `Too many messages from you. Try again in 120 s.` with a `Retry-After` header in seconds. |
| `500` | `Something went wrong`. Try again later. |

Every message and its fix: [Troubleshooting](/docs/troubleshooting). Every limit: [Limits](/docs/limits).

## Not in the API

- There's no API for your team's side (reading the inbox, replying as staff): that's the desk.
- No webhooks out of Junco yet. Users' replies arrive in your form when you fetch them.
- No pagination: a user's own ticket list is short.
