ConceptsPagination & sorting

Pagination & sorting

Endpoints that return lists share the same envelope:

{
  "page": 1,
  "resultsPerPage": 20,
  "totalCount": 4623,
  "totalPages": 232,
  "listings": [ /* items */ ],
  "attribution": { /* see Concepts → Attribution */ }
}

Query params

ParamDefaultMaxNotes
pageNum1unbounded (validated against totalPages)1-indexed
resultsPerPage20100Anything outside 1–100 returns 400.
sortByupdatedOnDescsee table below

Sort values for /listings

sortByEffect
updatedOnDesc (default)Most recently modified first
priceAscCheapest first
priceDescMost expensive first
sqftDescLargest first
createdDescNewest in our database first

Anything else falls back to the default — no error, just safe behavior.

How to walk all pages

Don’t ask for the full result set in one shot — paginate. Pseudocode:

let page = 1;
let totalPages = 1;
do {
  const res = await fetch(`/listings?pageNum=${page}&resultsPerPage=100`, {
    headers: { 'X-API-KEY': key },
  }).then((r) => r.json());
 
  process(res.listings);
  totalPages = res.totalPages;
  page += 1;
} while (page <= totalPages);

Don’t ramp resultsPerPage past 100 — the server caps it and you waste a round-trip.

Tip: pre-filter aggressively

Pagination cost is real on big result sets — every page is a separate HTTP round-trip + SQL query. Filter as much as you can with ?city=, ?status=Active, ?minPrice= etc. before paginating. A typical “show me 3-bed condos in Windsor under $700k” query usually returns < 100 results total, so you’ll only hit one page.