Page cover

πŸ“ƒPagination

Pagination is exclusive to the GetConversation endpoints

  • /api/Chat/GetConversations/{agentid}/{results}/{skip}/{metadatasearch}

  • /api/Chat/GetConversations/{agentid}

  • /api/Chat/GetConversations

The Semantic Meaning of the pagination-related parameters are:

  1. results : Page Length

  2. skip : Starting Index

    1. Corresponds with (page_num * page_size)

πŸ”’ How to Fetch a Specific Page of Data

Fetching page-based data is simple when you understand how to calculate what to fetch and from where to start.

πŸ“˜ What You Need to Know

To request Page N from our API, you’ll need to provide two key numbers:

Parameter
Meaning
Example (for Page 3, 20 items/page)

results

How many items you want (page size)

20

skip

Where to start from in the total list

(3 - 1) * 20 = 40

πŸ” Formula: skip = (pageNumber - 1) * results

This formula tells the API where in your data to begin. The results value tells it how many items to return from that point.

🧭 Understanding API Parameters (with Purpose)

Parameter
Type
Required?
Description

agentid

string

No*

The ID of the agent you want data for. Omit if you want system-wide data.

results

integer

Yes

Number of records per page. Defaults to 20 if not specified.

skip

integer

Yes

Offset in the dataset (calculated based on current page).

metadatasearch

string

No

Optional keyword filter. Use "" (empty string) if not filtering.


Below are plug-and-play functions that dynamically support both API routes:

  • /api/Chat/GetConversations/ (when agent ID is not known)

  • /api/Chat/GetConversations/{agentid} (when it is)

These helpers calculate the correct skip, and let your app specify the page without worrying about the URL details.

βœ… If agentid is omitted, just use /api/Chat/GetConversations β€” the API will still respond with paginated data.

Note: For your own app integrating with our API, it is typical in pagination to first get the total number of query-able items in the not-paginated data source so that you know for instance what the max.

πŸ›  Pagination Helper (Agent Handling)


🐍 Python Helper

import requests

def fetch_conversations(agentid=None, page=1, results=20, metadatasearch=""):
    skip = (page - 1) * results
    base = "https://yourdomain.com/api/Chat/GetConversations"
    
    if agentid:
        url = f"{base}/{agentid}"
    else:
        url = base

    params = {
        "results": results,
        "skip": skip,
        "metadatasearch": metadatasearch,
    }

    response = requests.get(url, params=params)
    return response.json()
    
def alt_fetch_conversations(agentid=None, page=1, results=20, metadatasearch=""):
    # Demonstrates the alternative way of calling GetConversations using only path parameters
    # E.g. `/api/Chat/GetConversations/{agentid}/{results}/{skip}/{metadatasearch}`
    skip = (page - 1) * results
    base = "https://yourdomain.com/api/Chat/GetConversations"
    
    if agentid is not None and \
        page is not None and \
        results is not None and \
        metadatasearch:
        
        url = f"{base}/{agentid}/{results}/{skip}/{metadatsearch}"
        response = requests.get(url)
        return response.json()
   else:  # If not all params have valid value, use GET params instead of path ones
       return fetch_conversations(agentid, page, results, metadatasearch)


πŸ§‘β€πŸ’Ό Example: Fetching Page 4 with Filter

Scenario: You want to load Page 4 of a conversation list filtered by the keyword β€œsales”, with 25 results per page.

Using the API directly:

GET /api/Chat/GetConversations/abc123?results=25&skip=75&metadatasearch=sales
  • page = 4

  • results = 25

  • skip = (4 - 1) * 25 = 75

With the helper:

fetch_conversations(agentid="abc123", page=4, results=25, metadatasearch="sales")

πŸ” Recap: Building a UI with Pagination

To integrate pagination smoothly into your UI:

  1. Set a default results value (e.g., 20 or 50)

  2. Track currentPage in your frontend or backend state

  3. When the user clicks β€œNext” or β€œPrevious”:

    • Update page

    • Recalculate skip

    • Re-fetch data using the helpers above

  4. Render the results into your UI

πŸ’‘ Pro tip: You can pre-fetch the next page in the background to create an β€œinstant” pagination experience.

Last updated