The GetBill API uses page-based pagination for endpoints that return lists of resources. You can specify the page number and items per page to navigate through large datasets.
# Get the first page of debts (default: 20 items)curl -X GET "https://getbill.io/external-api/v1/debts" \ -H "Authorization: Bearer YOUR_ACCESS_TOKEN"# Get the second page with 50 items per pagecurl -X GET "https://getbill.io/external-api/v1/debts?page=2&limit=50" \ -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
import requestsfrom typing import Iterator, Dict, Anyclass GetBillAPI: def __init__(self, access_token: str): self.access_token = access_token self.base_url = "https://getbill.io/external-api/v1" self.headers = { "Authorization": f"Bearer {access_token}", "Content-Type": "application/json" } def get_debts(self, page: int = 1, limit: int = 20, **filters) -> Dict[str, Any]: """Get a single page of debts""" params = {"page": page, "limit": limit, **filters} response = requests.get( f"{self.base_url}/debts", headers=self.headers, params=params ) response.raise_for_status() return response.json() def iter_all_debts(self, limit: int = 100, **filters) -> Iterator[Dict[str, Any]]: """Iterate through all debts across all pages""" page = 1 while True: response = self.get_debts(page=page, limit=limit, **filters) for debt in response["data"]: yield debt if page >= response["pagination"]["pages"]: break page += 1 def get_all_debts(self, **filters) -> list: """Get all debts as a list (use with caution for large datasets)""" return list(self.iter_all_debts(**filters))# Usageapi = GetBillAPI("your_access_token")# Get first pagefirst_page = api.get_debts(page=1, limit=50)# Process all debts efficientlyfor debt in api.iter_all_debts(status="active"): print(f"Processing debt {debt['id']}")# Get all debts at once (careful with memory)all_debts = api.get_all_debts(status="active")
// ✅ Good: Process items one page at a timeasync function processAllDebts() { let page = 1; let hasMore = true; while (hasMore) { const response = await api.getDebts({ page, limit: 100 }); // Process current page for (const debt of response.data) { await processDebt(debt); } hasMore = page < response.pagination.pages; page++; }}// ❌ Bad: Load everything into memoryasync function processAllDebts() { const allDebts = await api.getAllDebts(); // Could be huge! for (const debt of allDebts) { await processDebt(debt); }}
All pagination parameters can be combined with filtering parameters:
Copy
# Get second page of active debts with amounts over €1000curl -X GET "https://getbill.io/external-api/v1/debts?page=2&limit=50&status=active&amount_min=1000" \ -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
Filters are applied before pagination, so the total count reflects the filtered dataset, not all records.