TrackMe API Docs
Flow guides

Support Tickets

How a signed-in customer opens a support ticket, reads their tickets, and runs the chat-style reply thread with the support team — including why a "create" lands live and why a resolved ticket goes read-only.

This is the customer support surface, rooted at /api/v1/support/tickets. A signed-in user can open a ticket, list their tickets, read a single ticket, and carry on a chat-style reply thread with the support team. Every endpoint sits behind the api token guard — an anonymous call returns 401 AUTH_REQUIRED. Ownership is strict and per-user: you can only see and reply to your own tickets, and touching someone else's returns 403 FORBIDDEN.

Admin triage (agent replies and status changes) happens on a separate /api/v1/admin/support/* surface covered in Admin and the API reference. It drives the state transitions your app must react to, so those transitions are documented in the lifecycle table below.

Auth & headers on every call: Authorization: Bearer <oat_...>. Send Accept-Language: ar for Arabic error copy (persisted as your preferred language on the first authenticated request). Read meta.requestId from each response for support/tracing. All wire timestamps are UTC ISO-8601 with a trailing Z.

Response envelope is always one of:

{ "data": { /* payload */ }, "meta": { "requestId": "req_01..." } }
{ "error": { "code": "AUTH_REQUIRED", "message": "..." }, "meta": { "requestId": "req_01..." } }

There is no customer-side draft or pending pre-publish step. Resolved and closed tickets are read-only.

  • POST /api/v1/support/tickets creates the ticket live immediately with status: "open". There is no separate "submit/activate" call. Do not build a draft state.
  • The reverse is what bites: once a support agent sets the ticket to resolved or closed, any further reply returns 409 CONFLICT with code SUPPORT_TICKET_CLOSED. The thread cannot be revived from the customer side — the only path forward is to open a brand-new ticket.

The flow at a glance

Step 1 — Authenticate

Obtain a Bearer access token (oat_...) — see Authentication. Every call below requires it.

Step 2 — Open a ticket

POST /api/v1/support/tickets with subject, message, and an optional priority. The server creates it live with status: "open" (waiting on support) and priority defaulting to "normal". Returns 201 with the ticket.

Step 3 — List & read your tickets

GET /api/v1/support/tickets for the list (newest first), GET /api/v1/support/tickets/:id for one ticket. Both are scoped to you.

Step 4 — Load the reply thread

GET /api/v1/support/tickets/:id/messages (oldest first). The opening complaint lives on ticket.message, not in this thread — render the ticket body first, then the messages.

Step 5 — Reply (and react to agent replies)

POST /api/v1/support/tickets/:id/messages with { body }. A user reply on a pending ticket flips it back to open. When an agent replies on the admin surface, you receive an SSE support_message notification — refresh the thread instead of polling.

Step 6 — Handle resolution

When an agent sets the ticket to resolved or closed, further replies return 409 SUPPORT_TICKET_CLOSED. Detect this and prompt the user to open a new ticket — do not retry.

Per-step detail

GET /api/v1/support/tickets — list your tickets

Returns your tickets newest-first, scoped to the caller. 401 AUTH_REQUIRED if unauthenticated.

GET /api/v1/support/tickets HTTP/1.1
Authorization: Bearer oat_abc123
Accept-Language: en
{
  "data": {
    "items": [
      {
        "id": "tkt_01jq8z4c0e3p5q7r9s2t4w6x8z",
        "userId": "usr_01...",
        "subject": "Refund request — order TM-20260518-0019",
        "message": "I was charged twice. The second charge needs to be refunded.",
        "status": "open",
        "priority": "high",
        "assignedAdminId": null,
        "resolvedAt": null,
        "closedAt": null,
        "createdAt": "2026-06-21T09:00:00.000Z",
        "updatedAt": "2026-06-21T09:00:00.000Z"
      }
    ]
  },
  "meta": { "requestId": "req_01..." }
}

POST /api/v1/support/tickets — open a new ticket

Body: subject (2–200 chars, required), message (2–5000 chars, required), priority (optional, one of low / normal / high). priority defaults to "normal" server-side. Returns 201 with the created ticket at status: "open". 422 VALIDATION_ERROR on bad input, 401 if unauthenticated.

POST /api/v1/support/tickets HTTP/1.1
Authorization: Bearer oat_abc123
Content-Type: application/json

{
  "subject": "Refund request — order TM-20260518-0019",
  "message": "I was charged twice. The second charge needs to be refunded.",
  "priority": "high"
}
{
  "data": {
    "ticket": {
      "id": "tkt_01jq8z4c0e3p5q7r9s2t4w6x8z",
      "userId": "usr_01...",
      "subject": "Refund request — order TM-20260518-0019",
      "message": "I was charged twice. The second charge needs to be refunded.",
      "status": "open",
      "priority": "high",
      "assignedAdminId": null,
      "resolvedAt": null,
      "closedAt": null,
      "createdAt": "2026-06-21T09:00:00.000Z",
      "updatedAt": "2026-06-21T09:00:00.000Z"
    }
  },
  "meta": { "requestId": "req_01..." }
}

The ticket is actionable the instant this 201 returns — status is "open", never "new". There is nothing else to call to "publish" it. (If you see "new", "in_progress", or "assigned" in any older sample, ignore them — the live customer-facing set is exactly open | pending | resolved | closed.)

GET /api/v1/support/tickets/:id — read one ticket

Ownership is enforced (ticket.userId === user.id). Returns the same ticket shape as above. 403 FORBIDDEN if the ticket belongs to another user, 404 NOT_FOUND if the id does not exist, 401 if unauthenticated.

GET /api/v1/support/tickets/tkt_01jq8z4c0e3p5q7r9s2t4w6x8z HTTP/1.1
Authorization: Bearer oat_abc123

GET /api/v1/support/tickets/:id/messages — the reply thread

Same ownership gate as show. Returns the reply thread oldest-first. Each message is { id, ticketId, authorId, authorType, body, createdAt }, where authorType is "user" or "admin". 403 / 404 / 401 as for show.

GET /api/v1/support/tickets/tkt_01jq8z4c0e3p5q7r9s2t4w6x8z/messages HTTP/1.1
Authorization: Bearer oat_abc123
{
  "data": {
    "items": [
      {
        "id": "smg_01...",
        "ticketId": "tkt_01jq8z4c0e3p5q7r9s2t4w6x8z",
        "authorId": "adm_01...",
        "authorType": "admin",
        "body": "We've issued the refund — it should land in 3–5 business days.",
        "createdAt": "2026-06-21T09:30:00.000Z"
      }
    ]
  },
  "meta": { "requestId": "req_01..." }
}

The opening complaint text is ticket.message (returned on the ticket object), not the first row of this thread. The thread holds replies only. To show the full conversation, render ticket.message (as the customer's first message) followed by the /messages items.

POST /api/v1/support/tickets/:id/messages — reply

Body: body (1–5000 chars, required). Appends a message with authorType: "user". Returns 201 with the new message.

  • If the ticket was pending (waiting on you), this reply flips it back to open (waiting on support) — a side effect, there is no status endpoint on the customer side.
  • If the ticket is already resolved or closed, you get 409 CONFLICT with code SUPPORT_TICKET_CLOSED — open a new ticket instead.
  • 403 if not owner, 404 if missing, 422 on validation, 401 if unauthenticated.
POST /api/v1/support/tickets/tkt_01jq8z4c0e3p5q7r9s2t4w6x8z/messages HTTP/1.1
Authorization: Bearer oat_abc123
Content-Type: application/json

{ "body": "Any update on the refund?" }
{
  "data": {
    "message": {
      "id": "smg_02...",
      "ticketId": "tkt_01jq8z4c0e3p5q7r9s2t4w6x8z",
      "authorId": "usr_01...",
      "authorType": "user",
      "body": "Any update on the refund?",
      "createdAt": "2026-06-21T10:00:00.000Z"
    }
  },
  "meta": { "requestId": "req_01..." }
}

The 409 when the ticket is already resolved or closed:

{
  "error": {
    "code": "SUPPORT_TICKET_CLOSED",
    "message": "This ticket is closed. Open a new ticket to continue."
  },
  "meta": { "requestId": "req_01..." }
}

Live updates (SSE)

When a support agent replies on the admin surface, the server pushes an SSE notification to the ticket owner so the chat UI updates without polling:

  • type: "support_message", category: "support".
  • title is the ticket subject; body is the agent's reply truncated to 140 chars.
  • data: { ticketId, messageId }.

On receiving it, call GET /api/v1/support/tickets/:id/messages to refresh the thread (and re-read the ticket if you need the updated status). Do not poll. The support_message event arrives on your own SSE channel users/<yourId>/notifications — see Chat & Realtime (SSE) for how to subscribe to that stream.

Lifecycle

Status semantics are inverted from how they sound — label your UI by who is waiting, not by the raw enum word:

  • open = waiting on support to respond.
  • pending = waiting on the customer to respond.

State table

StateMeaningHow you got hereWhat's allowed next
openWaiting on supportTicket created (POST /support/tickets), or a customer reply on a pending ticketCustomer can reply; support can reply (→ pending), resolve, or close
pendingWaiting on the customerA support agent replied to an open ticket (admin surface)Customer reply flips it back to open; support can resolve or close
resolvedMarked done by support; resolvedAt stampedAgent set status resolved (admin surface)Read-only for the customer — replies return 409 SUPPORT_TICKET_CLOSED. Support can reopen or close
closedFinalized by support; closedAt stampedAgent set status closed (admin surface)Read-only for the customer — replies return 409 SUPPORT_TICKET_CLOSED. Support can reopen

Transitions

  • (none) → open via POST /api/v1/support/tickets (customer; creation always lands on open).
  • open → pending via an admin reply on POST /api/v1/admin/support/tickets/:id/reply (support; out of mobile scope — react to the resulting support_message SSE).
  • pending → open via POST /api/v1/support/tickets/:id/messages (customer; a reply auto-reopens — there is no direct status endpoint for customers).
  • open / pending → resolved via POST /api/v1/admin/support/tickets/:id/status { "status": "resolved" } (support; stamps resolvedAt).
  • open / pending / resolved → closed via POST /api/v1/admin/support/tickets/:id/status { "status": "closed" } (support; stamps closedAt).
  • resolved / closed → open / pending via POST /api/v1/admin/support/tickets/:id/status (support; reopen clears resolvedAt and closedAt).

The only transition a customer can trigger directly is (none) → open (create) and pending → open (reply). Everything else is admin-driven; the customer app observes it via the ticket's status and the support_message SSE.

Implementation Notes

Integration issueCorrect handling
Building a draft/submit step for new ticketsPOST /support/tickets creates the ticket live at status: "open". There is no "publish" call — treat the 201 as fully done.
Retrying a reply that returned 409A 409 SUPPORT_TICKET_CLOSED means the ticket is resolved or closed and cannot be revived. Prompt the user to open a new ticket, do not retry the same one.
Rendering status: "new" / "in_progress" / "assigned"Those are non-canonical legacy doc artefacts. The live set is exactly `open
Labeling the UI by the raw enum wordopen = waiting on support; pending = waiting on the customer. The words are inverted — label by who-is-waiting.
Looking for a customer "set status" endpointNo customer endpoint exists for direct status changes. The customer influences state only by replying (pending → open). resolved / closed / reopen are admin-only.
Treating /:id/messages as the whole conversationThe opening complaint is ticket.message on the ticket object — it is not a row in the thread. Render the ticket body + the thread together.
Sending priority: "medium"Allowed values are low / normal / high. The default is "normal" (not "medium", despite an older sample).
Expecting assignedAdminId to be set on createIt is null until an agent engages with the ticket.
Polling for agent repliesListen for the support_message SSE (category: "support", data: { ticketId, messageId }) and refresh the thread on receipt.
Reading/replying on another user's ticketOwnership is strict and silent: 403 FORBIDDEN for someone else's ticket, 404 NOT_FOUND for an unknown id. There is no shared/public view.
Hitting 422 on create/replyEnforce client-side: subject 2–200 chars, message 2–5000 chars on create; reply body 1–5000 chars.
Calling any endpoint without a tokenThe whole group is behind the api guard. A missing/expired oat_ token returns { error: { code: "AUTH_REQUIRED" } }.

On this page