LemuAIDocs

Guides · 5 min read

Searching with TQL

Find tickets with the Ticket Query Language: fields, operators, dates, sorting and examples

Open in ChatGPTOpen in ClaudeMarkdown

TQL (Ticket Query Language) is how you search tickets. It is the same language the LemuTickets app uses for filters, queues and saved views, so a filter you build in the app works in the API too.

Send a query as the q parameter of List and search tickets:

cURL
curl -G https://api.tickets.lemuai.com/v1/tickets \
  -H "Authorization: Bearer ltk_live_your_api_key" \
  --data-urlencode 'q=project = SUP AND status_category != done AND priority in (p1, p2) ORDER BY sla.next_due ASC'

How a query is built#

A query is one or more conditions joined with AND and OR, followed by an optional ORDER BY:

Text
field operator value [AND|OR field operator value ...] [ORDER BY field [ASC|DESC], ...]
  • AND binds tighter than OR. Use parentheses to group: (priority = p1 OR sla.breached = true) AND project = SUP.
  • Two conditions side by side without a keyword are joined with AND.
  • NOT in front of a condition or group negates it: NOT labels in (spam).
  • Keywords (AND, OR, NOT, IN, IS, EMPTY, ORDER BY, ASC, DESC) are not case sensitive. Field names are not case sensitive.
  • Put values with spaces or special characters in double or single quotes: status = "Waiting on customer".
  • A quoted text or a word on its own is a full-text search of the title and description: "refund not received". A ticket key on its own, like SUP-1042, finds that ticket.

Operators#

OperatorMeaningExample
=Equalspriority = p1
!=Does not equal (also matches tickets where the field is empty)status_category != done
> >= < <=Greater or less than (dates, numbers, priority)created >= -7d
~Contains (case insensitive)title ~ invoice
!~Does not containtitle !~ test
IN (...)Any of the valuespriority in (p1, p2)
NOT IN (...)None of the valuessource not in (email, slack)
IS EMPTYHas no valueassignee is empty
IS NOT EMPTYHas a valuedue is not empty

For priority, "greater" means more urgent: priority >= p2 finds p1 and p2.

Fields#

FieldWhat it matchesValues
projectThe projectKey (SUP), name or id
keyThe ticket keySUP-1042
typeThe ticket typeName (Complaint) or id
statusThe exact statusName ("In progress") or id
status_categoryThe status groupnew, open, waiting, done
priorityPriorityp1, p2, p3, p4
severitySeverityText
sourceWhere the ticket came fromvoice, whatsapp, web_chat, email, slack, teams, api, portal, web_form, manual, lemu_copilot, automation, journey
assigneeThe assigned personme(), email, name or user id
reporterWho created the ticketme(), email, name or user id
teamThe assigned teamName or id
requesterThe customer who raised itEmail, phone, name or requester id
accountThe customer's accountName or id
account.tierThe account's tierFor example enterprise
requester.vipRequester is marked VIPtrue or false
labelsLabels on the ticketLabel text. labels in (refund, urgent) matches tickets with any of them
titleThe titleText (use ~ to search inside it)
descriptionThe descriptionText
textFull-text search of title and descriptionText
createdWhen it was createdDate
updatedLast changeDate
resolvedWhen it was resolvedDate
closedWhen it was closedDate
dueThe due dateDate
first_responseFirst public replyDate
status_changedLast status changeDate
sla.next_dueThe next SLA deadlineDate
sla.breachedAn SLA target was missedtrue or false
escalation_levelHow many times it was escalatedNumber
reopenedHow many times it was reopenedNumber
csatThe customer's satisfaction scoreNumber
time_spentLogged work, in minutesNumber
restrictedVisible only to some peopletrue or false
parentThe parent ticketTicket key
watcherA user watching the ticketUser id
external_idYour own id for the ticketText
cf.<key>A custom fieldDepends on the field. Numbers can use > and <
ai.<key>A value the AI set during triage, such as ai.categoryText

status_category is usually better than status in integrations: each project names its statuses differently, but every status belongs to one of the four categories.

Dates#

Date fields accept:

  • Relative times from now: -30m, -12h, -7d, -2w for the past, +1d for the future. created >= -7d is "created in the last 7 days".
  • ISO dates and times: 2026-11-01 or 2026-11-01T09:00:00+05:30. Times without a zone are read as UTC.
  • Functions: now(), startOfDay(), endOfDay(), startOfWeek() (Monday), startOfMonth(). These use UTC.

Functions#

FunctionValue
me() or currentUser()The calling user. For an API key, the key's own user
now()The current time
startOfDay(), endOfDay()Start or end of today (UTC)
startOfWeek()Monday 00:00 of this week (UTC)
startOfMonth()The first of this month, 00:00 (UTC)

Sorting#

Add ORDER BY at the end with one or more fields, each ASC (default) or DESC. Empty values sort last. Without ORDER BY, the most recently updated tickets come first.

You can sort by created, updated, resolved, due, sla.next_due, key (or number), title, priority, status (or status_category), escalation_level, csat and status_changed.

Examples#

You wantQuery
Open tickets in one project, most urgent firstproject = SUP AND status_category != done ORDER BY priority ASC, created ASC
Breached or about to breach todaysla.breached = true OR sla.next_due <= endOfDay()
Unassigned high-priority ticketsassignee is empty AND priority >= p2 AND status_category in (new, open)
One customer's tickets this monthrequester = "priya@example.com" AND created >= startOfMonth()
Enterprise accounts waiting on youaccount.tier = enterprise AND status_category = open
Complaints from WhatsApp last weektype = Complaint AND source = whatsapp AND created >= -1w
A custom field valuecf.order_id = "58213"
Ticket synced from your ERPexternal_id = "ERP-CMP-58213"
Free text"refund not received" AND project = SUP

Checking a query#

Send a query to POST /v1/tql/validate to check it before you save it in your system:

cURL
curl -X POST https://api.tickets.lemuai.com/v1/tql/validate \
  -H "Authorization: Bearer ltk_live_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{ "q": "project = SUP AND priorty = p1" }'
JSON
{
  "valid": false,
  "message": "Unknown field priorty",
  "data": { "field": "priorty" },
  "fields": ["project", "key", "type", "status", "..."]
}

A valid query returns "valid": true and the same fields list. When a query in List and search tickets is invalid, the request fails with 422 and a tql_* error code.

Was this page helpful?