Getting Started
Pagination
How tools that return lists split their results into pages, and how to read them all
Tools that can return many rows, such as list_agents, query_conversations, query_tickets and list_sources, return one page at a time. You ask for a page by number and keep going until the response says there's nothing more.
How It Works
Tools API lists use page numbers. Pages start at 1 and hold a fixed number of rows that you don't choose: 20 for most tools. Send the same arguments with the next page to read on.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
page | integer | Required on most list tools; 1 on list_agents | The page to return, from 1. |
Response Shape
Most list tools return their rows in items with the page details beside them:
{
"success": true,
"data": {
"items": [],
"page": 1,
"total": 270,
"hasMore": true
}
}| Field | Type | Description |
|---|---|---|
items | array | The page of results. list_agents names this array agents. |
page | integer | The page you asked for. |
total | integer | How many rows match, across all pages. |
hasMore | boolean | true when there's another page after this one. |
list_sources puts the page details in a pagination object instead:
{
"success": true,
"data": {
"items": [],
"pagination": { "page": 1, "limit": 20, "total": 21, "pages": 2 }
}
}Read on while pagination.page is less than pagination.pages.
Page sizes
| Tool | Rows per page | Pages through |
|---|---|---|
list_agents | 20 | page |
query_conversations | 20 | page |
query_tickets | 20 | page |
list_sources, find_sources_by_status, list_source_pages | 20 | page |
get_conversation_detail | 20 messages | page, oldest first; newestFirst: true starts from the latest |
get_source_content | 10 documents | page |
get_outbound | 25 campaigns | page |
get_outbound_campaign | 50 recipients | page |
get_ticket_detail | Comment excerpts | offset, then the nextOffset it returns (null at the end) |
read_source_document, agent_instructions | Text in chunks | offset, then the nextOffset each response returns |
Paginating Through All Results
Keep every argument the same and raise page until hasMore is false:
async function fetchAllTickets(agentId, apiKey) {
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 ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ chatbotId: agentId, page, status: "open" }),
}
);
const { data } = await response.json();
tickets.push(...data.items);
hasMore = data.hasMore;
page += 1;
}
return tickets;
}import requests
def fetch_all_tickets(agent_id: str, api_key: str):
tickets = []
page = 1
while True:
response = requests.post(
"https://api.qwryai.com/public/v1/tools/query_tickets",
headers={"Authorization": f"Bearer {api_key}"},
json={"chatbotId": agent_id, "page": page, "status": "open"},
)
data = response.json()["data"]
tickets.extend(data["items"])
if not data["hasMore"]:
break
page += 1
return ticketsDate-Ranged Lists
Conversation tools such as query_conversations, search_conversations and get_conversation_facets read one UTC date range at a time. startDate and endDate are required, written YYYY-MM-DD, include both days, and can span at most 184 days. To read a longer history, split it into ranges and page through each.
Message Pagination
get_conversation_detail returns the conversation and its messages, 20 per page, oldest first (order says which way you're reading):
- Page
1holds the first 20 messages of the conversation. - Each next page continues forward in time;
mayHaveMoreistruewhile there may be more messages. - Send
newestFirst: trueto start from the most recent messages instead.
Messages come back as 800-character excerpts. Add fullText: true for the full text.
Mobile SDK Pagination
The iOS and Android SDKs list a signed-in customer's own conversations and messages with cursor pagination, which the SDKs handle for you:
| Parameter | Type | Default | Description |
|---|---|---|---|
cursor | string | — | The pagination.cursor from the previous response. Leave it out for the first page. |
limit | integer | 20 | Items per page, 1 to 100. |
{
"data": [],
"pagination": {
"cursor": "WzE3OTY1OTk0MjQwMDAsIjQ5ZTkyYWU2Il0",
"hasMore": true,
"total": 42
}
}Conversations come newest first. Messages page backward from the newest, and each page lists its messages oldest to newest. cursor is null on the last page. Treat cursors as opaque: a cursor that's been changed returns 400 VALIDATION_INVALID_BODY.