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)async function fetchConversations({ agentId = null, page = 1, results = 20, metadatasearch = "" }) {
const skip = (page - 1) * results;
const baseUrl = "https://yourdomain.com/api/Chat/GetConversations";
const url = new URL(agentId ? `${baseUrl}/${agentId}` : baseUrl);
url.searchParams.set("results", results);
url.searchParams.set("skip", skip);
url.searchParams.set("metadatasearch", metadatasearch);
const res = await fetch(url);
return await res.json();
}Last updated