Pagination Helper

🛠 Pagination Helper (Agent Handling)


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

🐍 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)

Last updated