Skip to content
QwryAI
Documentation
Pages

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

ArgumentTypeDefaultDescription
pageintegerRequired on most list tools; 1 on list_agentsThe page to return, from 1.

Response Shape

Most list tools return their rows in items with the page details beside them:

JSON
{
  "success": true,
  "data": {
    "items": [],
    "page": 1,
    "total": 270,
    "hasMore": true
  }
}
FieldTypeDescription
itemsarrayThe page of results. list_agents names this array agents.
pageintegerThe page you asked for.
totalintegerHow many rows match, across all pages.
hasMorebooleantrue when there's another page after this one.

list_sources puts the page details in a pagination object instead:

JSON
{
  "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

ToolRows per pagePages through
list_agents20page
query_conversations20page
query_tickets20page
list_sources, find_sources_by_status, list_source_pages20page
get_conversation_detail20 messagespage, oldest first; newestFirst: true starts from the latest
get_source_content10 documentspage
get_outbound25 campaignspage
get_outbound_campaign50 recipientspage
get_ticket_detailComment excerptsoffset, then the nextOffset it returns (null at the end)
read_source_document, agent_instructionsText in chunksoffset, then the nextOffset each response returns

Paginating Through All Results

Keep every argument the same and raise page until hasMore is false:

JavaScript
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;
}
Python
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 tickets

Date-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 1 holds the first 20 messages of the conversation.
  • Each next page continues forward in time; mayHaveMore is true while there may be more messages.
  • Send newestFirst: true to 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:

ParameterTypeDefaultDescription
cursorstring—The pagination.cursor from the previous response. Leave it out for the first page.
limitinteger20Items per page, 1 to 100.
JSON
{
  "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.

Explore the documentation