# Tickets

List, create, update, merge and bulk edit tickets.

Scopes: `tickets:read` to read, `tickets:write` to change.

| Method | Path | Description |
| --- | --- | --- |
| `GET` | `/v1/tickets` | List tickets |
| `GET` | `/v1/tickets/counts` | Counts for the sidebar |
| `GET` | `/v1/tickets/summary` | Counts for a whole list, every page of it |
| `POST` | `/v1/tickets` | Create a ticket |
| `GET` | `/v1/tickets/{id}` | Get a ticket |
| `PATCH` | `/v1/tickets/{id}` | Update a ticket |
| `DELETE` | `/v1/tickets/{id}` | Delete a ticket (soft delete) |
| `POST` | `/v1/tickets/bulk` | Update or delete many tickets |
| `GET` | `/v1/tickets/deleted` | The trash: deleted tickets, who deleted each and when (admins) |
| `POST` | `/v1/tickets/{id}/restore` | Restore a deleted ticket (admins) |
| `POST` | `/v1/tickets/{id}/merge` | Merge into another ticket |
| `GET` | `/v1/tickets/{id}/activities` | The ticket's activity, ascending |
| `GET` | `/v1/tickets/{id}/wiki` | The wiki pages you can see that mention the ticket. Also needs `wiki:read`. See [Wiki](/api/resources/wiki/#tickets-and-the-help-center) |

Messages are on their own page: [Messages and attachments](/api/resources/messages/).

## The ticket object

```ts
type Ticket = {
  id: string;
  number: number;
  alias: string | null; // optional workspace-unique reference; not an authorization token
  subject: string;
  status: "open" | "pending" | "on_hold" | "solved" | "closed";
  priority: "low" | "normal" | "high" | "urgent";
  severity: "sev1" | "sev2" | "sev3" | "sev4" | null; // business impact, sev1 the most severe
  channel: "email" | "chat" | "api" | "portal";
  mailbox_id: string | null;
  contact: ContactRef | null;
  assignee: UserRef | null;
  team_id: string | null;
  tags: { id: string; name: string; color: LabelColor; group_id: string | null }[];
  sla: { policy_id: string; first_response_due_at: string | null; resolution_due_at: string | null; breached: boolean } | null;
  first_responded_at: string | null;
  solved_at: string | null;
  snoozed_until: string | null;
  last_message_at: string;
  last_customer_message_at: string | null;
  last_message_preview: string;
  // The newest internal note a member or an API key wrote on the ticket, or null.
  // Side conversation messages, automation and Ollie notes, deleted notes and notes sent as a reply are left out.
  last_note: {
    id: string;
    preview: string; // up to 200 characters, whitespace collapsed
    author: { type: "user" | "api"; name: string; user: UserRef | null };
    created_at: string;
    edited_at: string | null;
  } | null;
  message_count: number;
  spam: boolean;
  csat: { score: number; comment: string } | null;
  custom: Record<string, unknown>;
  fields: Record<string, FieldValue>; // custom fields, by key
  created_at: string;
  updated_at: string;
};
```

## List tickets

```sh
curl "https://api.opendesk.sh/v1/tickets?status=open,pending&assignee=none&sort=due&order=asc" \
  -H "Authorization: Bearer od_live_..."
```

| Filter | Values |
| --- | --- |
| `status` | comma-separated statuses |
| `priority` | comma-separated priorities |
| `severity` | comma-separated `sev1` to `sev4`, and `none` for tickets without one |
| `assignee` | `me`, `none` or a user id |
| `team_id` | comma-separated team ids, `mine` (your teams) and `none`: tickets of any of them |
| `team_not` | the same values: tickets of none of them |
| `team_members` | `true`: with `team_id`, also the tickets assigned to the leads and members of the teams it names |
| `mailbox_id`, `contact_id`, `view_id` | ids |
| `mailbox_not` | comma-separated mailbox ids: tickets whose reply address is none of them |
| `contact_not` | comma-separated contact ids: tickets whose contact is none of them |
| `company_not` | comma-separated company ids: tickets whose contact belongs to none of them |
| `tag` | comma-separated label names: tickets carrying any of them |
| `tag_not` | comma-separated label names: tickets carrying none of them |
| `untagged` | `true` for tickets carrying no label |
| `field.<key>`, `field.<key>[<op>]` | a [custom field filter](/api/resources/labels-fields/#filter-and-sort) |
| `channel` | `email`, `chat`, `api`, `portal` |
| `channel_not` | comma-separated channels: tickets on none of them |
| `q` | full-text search, an exact ticket alias, or a ticket number |
| `spam` | `true` or `false` |
| `merged` | `false` leaves out tickets merged into another, `true` lists only those; both by default |
| `sort` | `last_message_at`, `created_at`, `priority`, `severity` (sev1 first, none last), `due`, `field.<key>` |
| `order` | `asc` or `desc` |

Plus [`limit` and `cursor`](/api/pagination/).

`GET /v1/tickets/{id}` also accepts an alias, case-insensitively. Aliases follow the same workspace and private-team visibility rules as UUID and number lookups. Agents can set or clear an alias with `PATCH /v1/tickets/{id}`; use 2 to 40 letters, numbers or hyphens, including at least one letter. UUID forms, including compact hexadecimal and wrapped forms, are reserved for ticket IDs. An alias is a lookup convenience, not proof of identity or permission.

## Counts

```sh
curl https://api.opendesk.sh/v1/tickets/counts -H "Authorization: Bearer od_live_..."
```

```json
{ "unassigned": 4, "mine": 7, "open": 23, "pending": 9, "on_hold": 2, "solved": 310, "spam": 1, "views": { "<view_id>": 5 } }
```

## Summarize a list

`GET /v1/tickets/summary` takes the filters of `GET /v1/tickets` and counts every ticket of that list, not one page.

```sh
curl "https://api.opendesk.sh/v1/tickets/summary?view_id=<view_id>" -H "Authorization: Bearer od_live_..."
```

```json
{ "complete": true, "total": 115, "awaiting": 36, "urgent": 2, "overdue": 9, "due_soon": 4 }
```

`awaiting` counts open and pending tickets where the customer wrote last, `overdue` those past the due time that applies or with an SLA breach recorded, and `due_soon` those due within the hour. A list of more than 10 000 tickets, or a full-text search (`q`), is not counted: `complete` is then `false` and every count 0.

## Create a ticket

```sh
curl https://api.opendesk.sh/v1/tickets \
  -H "Authorization: Bearer od_live_..." \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "subject": "Refund for order 1234",
    "contact": { "email": "ana@example.com", "name": "Ana" },
    "channel": "email",
    "mailbox_id": "0192f0c4-...",
    "body_html": "<p>Hi Ana, your refund is on its way.</p>",
    "kind": "reply",
    "priority": "high",
    "tags": ["billing"],
    "status": "pending"
  }'
```

| Field | Notes |
| --- | --- |
| `subject` | required, except for a chat |
| `contact_id` or `contact` | an existing contact, or `{ email, name }` to find or create one |
| `channel` | `email`, `api` or `chat` |
| `mailbox_id` | the mailbox to send from, for email tickets |
| `widget_id` | the widget a chat opens in |
| `body_html` | the first message |
| `kind` | `reply` or `note` |
| `direction` | `outbound` (default) or `inbound`: with `inbound`, a `reply` is stored as the contact's own message, as if they had emailed it, and nothing is sent. Needs a contact; takes no `cc` or `bcc` |
| `priority`, `severity`, `assignee_id`, `team_id`, `tags`, `fields`, `status` | optional |

An `email` ticket created with a `reply` sends that reply to the contact from the mailbox. When that mailbox has no way to send (`sending: "system_off"`, see [Mailboxes](/api/resources/mailboxes/#sending-through-opendesk)), the request is `422 mailbox_cannot_send` and no ticket is created.

### Start a chat

A `chat` ticket opens a conversation in the chat widget on your site, with a contact the widget knows. The first message is a `reply`; the subject may be left out, and the chat is named after the message.

```sh
curl https://api.opendesk.sh/v1/tickets \
  -H "Authorization: Bearer od_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "channel": "chat",
    "contact_id": "0192f0c4-...",
    "body_html": "<p>Hi Ana, your order shipped today.</p>"
  }'
```

A chat reaches only someone whose identity the widget proves: a contact who signed in through [identity verification](/guides/live-chat/identity-verification/), or a visitor who used the chat in the last 90 days from the same browser and whom you know only from the chat. An email address a visitor types proves nothing, so once mail from that address, a call or any other ticket is on their contact, only identity verification reaches them. Contacts carry `chat_reachable` when a chat reaches them in some brand's widget; a chat in one brand needs them to have used that brand's chat, or to be verified. Anyone else answers `422 chat_unreachable`: email them instead.

Without `widget_id`, the chat opens in the widget the contact used last, else the brand's first widget that is on. The visitor sees it the next time the widget loads, with a count on the launcher and a preview of the message; while they are away it also goes to their email when the widget's email follow-up is on. A chat a person starts stays with the team: Ollie does not answer in it. The team can start at most 10 chats with one contact an hour.

## Get a ticket

`id` can be the UUID, the number, or `#` and the number (URL-encoded as `%23`).

```sh
curl https://api.opendesk.sh/v1/tickets/1042 -H "Authorization: Bearer od_live_..."
```

## Update a ticket

```sh
curl -X PATCH https://api.opendesk.sh/v1/tickets/1042 \
  -H "Authorization: Bearer od_live_..." \
  -H "Content-Type: application/json" \
  -d '{ "status": "solved", "tags": ["billing", "refund"] }'
```

Fields: `subject`, `status`, `priority`, `severity` (`null` clears), `contact_id` (a contact in this workspace), `assignee_id`, `team_id`, `snoozed_until`, `spam`, `tags` (replaces the set), `add_tags`, `remove_tags`, `fields` (merged, `null` clears), `custom`. Changing `contact_id` changes the recipient of future replies and records `contact_changed`; past messages stay as sent. A live chat stays with the visitor who started it, so changing its contact answers `422`, and a bulk update cannot change contacts. The update publishes `ticket.updated` with `contact_id` in `changes`. See [Labels and custom fields](/api/resources/labels-fields/) for the label rules and value types. Solving a ticket while a required field is empty answers `422 field_required`. Changing `priority`, `severity`, `team_id`, `spam` or labels removes Ollie's pending suggestion for that field (see [Decisions](/api/resources/ai/#decisions)).

## Bulk update

```sh
curl https://api.opendesk.sh/v1/tickets/bulk \
  -H "Authorization: Bearer od_live_..." \
  -H "Content-Type: application/json" \
  -d '{ "ids": ["...", "..."], "patch": { "status": "closed" } }'
```

Send `{ "ids": [...], "delete": true }` to delete instead.

## Trash

Deleting a ticket takes it out of every list, view and search, but keeps it: who deleted it (a member, or an API key) and when are recorded, and an admin can bring it back. `GET /v1/tickets/deleted` lists the deleted tickets, newest first, 50 at a time (`limit` up to 100, the page's `next_before` as `before` for the next one, `q` for a number or words of the subject). Each row has `deleted_at`, `deleted_by` (`{ id, name, email }`) or `deleted_by_api_key` (`{ id, name }`), both `null` for an automation's delete, and `merged_into_number` for a ticket merged into another.

```sh
curl -X POST https://api.opendesk.sh/v1/tickets/1234/restore   -H "Authorization: Bearer od_live_..."
```

Restoring brings the ticket back as it was and answers it. A ticket merged into another is `409`: its conversation lives on that ticket. Both routes need an admin, or a key with `tickets:read` and `tickets:write`.

## Your reply draft

The app saves the reply a member is writing, so it comes back after a refresh or on another device. It is private to the member and one per ticket.

| Method | Path | |
| --- | --- | --- |
| `GET` | `/v1/tickets/{id}/reply-draft` | `{ "draft": { ticket_id, body_html, attachments, updated_at } }`, or `null` |
| `PUT` | `/v1/tickets/{id}/reply-draft` | `{ body_html, attachment_ids? }` saves it, replacing the one before. Nothing in it discards it |
| `DELETE` | `/v1/tickets/{id}/reply-draft` | discards it (`204`) |

These need a signed-in member with the agent role; an API key gets `403`. `attachment_ids` are your uploads that are not on a message yet. Sending your reply on the ticket clears the draft; a teammate's reply does not. A draft untouched for 30 days is removed.

## Merge

```sh
curl https://api.opendesk.sh/v1/tickets/1042/merge \
  -H "Authorization: Bearer od_live_..." \
  -H "Content-Type: application/json" \
  -d '{ "into_id": "1038" }'
```

Every message, call, third-party thread and label moves to the target, and this ticket is closed. The answer is the ticket merged into. When `into_id` was itself merged, the merge goes into the ticket it went into, following the chain, and answers that ticket; `409` when that is this very ticket. A ticket that was open, pending or on hold, merged into a solved or closed one, reopens it, with a status change on its timeline. Apart from setting its status, this is the only way a closed ticket opens again: the customer's messages and their email leave it closed.

## Activities

`GET /v1/tickets/{id}/activities` returns the timeline entries that are not messages. An entry an API key made (`actor.type` `"api"`) names the key in `actor.api_key` (`{ id, name }`), and its id in `data.api_key_id`; `api_key` is `null` for an entry recorded before keys were, and once the key is deleted.

| Type | Data |
| --- | --- |
| `status_changed`, `priority_changed`, `severity_changed`, `assigned` | `{ from, to }`. A `status_changed` with `reason: "sender_unverified"` and `message_id` has `from` equal to `to`: a reply that failed sender checks left the status as it was |
| `team_changed` | |
| `tagged`, `untagged` | `{ tag }` |
| `sla_breached` | `{ kind }` |
| `merged` | `{ into }` |
| `csat_received` | `{ score }` |
| `contact_changed` | `{ from, to }`, each `{ id, name }` (the name, else the email) or `null` |

## Events

`ticket.created`, `ticket.updated` (with a `changes` list), `ticket.deleted` and `activity.created`. See the [events catalog](/api/events/).
