# Helpdesk > Read and search your agent's tickets, and manage Helpdesk statuses, teams, rules and macros from code The helpdesk tools work on the same tickets your team handles under **Tickets** in the dashboard. You can list and filter tickets, search them by number, title or customer, read a ticket with its comments, and pull counts and analytics into your own reports. With a settings key you can also manage the Helpdesk itself: ticket statuses, teams, triggers, automations, macros, tags, shifts and webhooks. Tickets are numbered per workspace as `TKT-1`, `TKT-2` and so on. Tools that read one ticket take that number as `ticketId`. A ticket's `source` records where it started, such as `chat` or a connected helpdesk like `freshdesk`. ## Statuses Each ticket's status belongs to one of six fixed categories: `open`, `in_progress`, `on_hold`, `waiting_on_customer`, `resolved` and `closed`. Inside each category you can add your own statuses in **Settings › Helpdesk › Statuses**; one per category is the default. | Tool | Does | | - | - | | `query_tickets` with `status` | Filters tickets by category. | | `get_ticket_counts` | Counts tickets by current status, plus unassigned tickets. | | `get_helpdesk_page` with `"page": "statuses"` | Lists the statuses with their ticket counts. | | `save_ticket_status` | Adds a status, or renames, describes, archives or makes one the default. `customer_name` is the name customers see. | | `reorder_ticket_statuses` | Reorders one category's statuses. | ## Assignment and routing `query_tickets` filters by `assigneeId` or `"unassigned": true`, never both at once. Each ticket returns `assignedAgentId` and `assignedAgentName`. `list_helpdesk_agents` lists the members tickets can be assigned to. Routing is set up as Helpdesk rules rather than per ticket: | Tool | Does | | - | - | | `save_helpdesk_team` | Adds or changes a team: its members, assignment strategy (`manual`, `round_robin` or `balanced`), workload limit and default. | | `save_helpdesk_rule` | Adds or changes a trigger or automation, with its conditions and actions. | | `set_helpdesk_rule_enabled` | Turns a trigger or automation on or off. | | `save_helpdesk_shift`, `assign_helpdesk_shift`, `save_time_off` | Working hours and time off. | Reading these settings needs **Manage conversations and helpdesk**. Changing them needs **Change agent settings**, and like every change they return a review you apply. See [Agents › Reviewed updates](/docs/api-reference/v2/agents#reviewed-updates). ## Messages `get_ticket_detail` returns a ticket with its description and its comments in pages. Start with `"offset": 0` and continue with the `nextOffset` it returns until that's `null`. Internal comments are included for members whose role can see them. ```bash curl -X POST 'https://api.qwryai.com/public/v1/tools/get_ticket_detail' \ -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{"chatbotId": "YOUR_AGENT_ID", "ticketId": "TKT-73", "offset": 0}' ``` ```json { "success": true, "data": { "ticketId": "TKT-73", "source": "chat", "assignedAgentId": null, "assignedAgentName": null, "title": "Late delivery for order 1043", "category": "general", "priority": "medium", "status": "open", "timestamps": { "created": "2026-11-30T18:15:02.074Z", "updated": "2026-11-30T18:56:55.709Z", "assigned": null, "resolved": null, "closed": null }, "respondedAt": null, "description": "My delivery for order 1043 is two weeks late. Please help me resolve this.", "descriptionTruncated": false, "comments": [], "nextOffset": null } } ``` The ticket tools read; they don't reply. To answer the customer from code, reply in the ticket's conversation with `send_agent_message`, which takes the conversation over for the key's creator, or add a private `add_internal_note`. ## Searching and reporting | Tool | Returns | | - | - | | `query_tickets` | Tickets, 20 per page, filtered by status, assignee, channel, creation dates and title text. `view_id` applies a saved view. | | `search_tickets` | Up to 20 tickets matching a ticket number, title or description, or (`"filter": "customers"`) the customers who opened tickets, by name, email, phone or company. | | `list_saved_views` | Your ticket views, as the Tickets sidebar shows them. | | `list_tags`, `list_custom_fields` | The agent's ticket tags and custom fields. | | `get_helpdesk_overview` | Daily ticket volume, sources, statuses and resolutions for a date range. | | `get_ticket_resolution_analytics` | Daily resolutions and average resolution time. | | `get_agent_performance` | Replies, notes, resolutions and assignments per team member. | ### Access Every ticket tool needs **Manage conversations and helpdesk**. Reading Helpdesk settings needs the same; changing them needs **Change agent settings**. A key never does more than its creator's role allows. ### Paging `query_tickets` pages by number: raise `page` until `hasMore` is `false`. Date filters need both `startDate` and `endDate`, written `YYYY-MM-DD`. See [Pagination](/docs/api-reference/v2/pagination). ### Pull yesterday's tickets every day ```javascript const yesterday = new Date(Date.now() - 86400000).toISOString().slice(0, 10); const tickets = []; let page = 1; let hasMore = true; while (hasMore) { const response = await fetch("https://api.qwryai.com/public/v1/tools/query_tickets", { method: "POST", headers: { Authorization: "Bearer YOUR_API_KEY", "Content-Type": "application/json" }, body: JSON.stringify({ chatbotId: "YOUR_AGENT_ID", startDate: yesterday, endDate: yesterday, page }), }); const { data } = await response.json(); tickets.push(...data.items); hasMore = data.hasMore; page += 1; } console.log(`${tickets.length} tickets opened yesterday`); ``` > [!TIP] > > To be told about tickets as they happen instead of polling, add a Helpdesk webhook with `add_helpdesk_webhook`. It fires when tickets open or close or a teammate takes over. See [Webhooks](/docs/developer-guides/webhooks). ## Endpoints > [card] List tickets | /docs/api-reference/v2/helpdesk/list-tickets | Filter and page through tickets with query_tickets. > [card] Search tickets | /docs/api-reference/v2/helpdesk/search-tickets | Find tickets by number, title or customer. > [card] Get a ticket | /docs/api-reference/v2/helpdesk/get-a-ticket | One ticket with its description and status. > [card] List ticket messages | /docs/api-reference/v2/helpdesk/list-ticket-messages | A ticket's comments, page by page. > [card] Add a message to a ticket | /docs/api-reference/v2/helpdesk/add-a-message-to-a-ticket | Reply in the ticket's conversation as a teammate. > [card] List teams | /docs/api-reference/v2/helpdesk/list-teams | The agent's Helpdesk teams and their members. > [card] List ticket statuses | /docs/api-reference/v2/helpdesk/list-ticket-statuses | The statuses in each category. ## Error codes Helpdesk-specific error codes beyond the standard [authentication and rate-limiting errors](/docs/api-reference/v2/error-handling): | Code | HTTP | Description | | - | - | - | | `INVALID_ARGUMENTS` | 400 | An argument failed the tool's schema, such as an unknown `status`. | | `VALIDATION_INVALID_BODY` | 409 | Only one of `startDate` and `endDate` was sent, both `assigneeId` and `unassigned` were sent, or `view_id` doesn't match a saved view. | | `INSUFFICIENT_PERMISSION` | 403 | The key doesn't hold **Manage conversations and helpdesk**, or **Change agent settings** for a settings change. | | `CHATBOT_NOT_FOUND` | 404 | No agent with that `chatbotId` in your workspace. |