Sorting and pagination

Order a list and read it a page at a time.

On this page

Sorting#

sorts is a JSON array of { "fieldId": "…", "direction": "asc" | "desc" }. The first entry sorts first. It takes up to 20 entries.

cURL
curl --fail-with-body -G "$JEMERO_URL/objects/companies/records" \
  -H "Authorization: Bearer $JEMERO_API_KEY" \
  --data-urlencode "sorts=[{\"fieldId\":\"$CREATED_AT_FIELD_ID\",\"direction\":\"desc\"}]"
Node.js
const sorts = [{ fieldId: process.env.CREATED_AT_FIELD_ID, direction: 'desc' }];
const url = new URL(`${process.env.JEMERO_URL}/objects/companies/records`);
url.search = new URLSearchParams({ sorts: JSON.stringify(sorts) });

const response = await fetch(url, {
  headers: { Authorization: `Bearer ${process.env.JEMERO_API_KEY}` },
});
if (!response.ok) throw new Error(`${response.status} ${await response.text()}`);
console.log((await response.json()).records.map((record) => record.displayValue));
Python
import json
import os
import requests

sorts = [{"fieldId": os.environ["CREATED_AT_FIELD_ID"], "direction": "desc"}]
response = requests.get(
    f"{os.environ['JEMERO_URL']}/objects/companies/records",
    headers={"Authorization": f"Bearer {os.environ['JEMERO_API_KEY']}"},
    params={"sorts": json.dumps(sorts)},
    timeout=30,
)
response.raise_for_status()
print([record["displayValue"] for record in response.json()["records"]])

You can sort by text, number, currency, email, phone, url, full_name, rating, date, date_time, checkbox and select fields, and by createdAt and updatedAt.

  • select sorts by the order of its options, not their labels.
  • currency sorts by the amount, whatever the currency.
  • Empty values come last in both directions.
  • Other types, including createdBy and updatedBy, answer 400.

With no sort, records come in the order shown in Jemero, which members can change by dragging. Newer records are first until someone does.

Pagination#

Use page (from 1) and pageSize (1–100, default 50). The answer repeats both, with total and totalIsCapped.

Read until a page returns fewer records than pageSize:

Node.js
const records = [];
const sorts = JSON.stringify([
  { fieldId: process.env.CREATED_AT_FIELD_ID, direction: 'asc' },
]);

for (let page = 1; ; page += 1) {
  const url = new URL(`${process.env.JEMERO_URL}/objects/companies/records`);
  url.search = new URLSearchParams({ page, pageSize: 100, sorts });
  const response = await fetch(url, {
    headers: { Authorization: `Bearer ${process.env.JEMERO_API_KEY}` },
  });
  if (!response.ok) throw new Error(`${response.status} ${await response.text()}`);
  const body = await response.json();
  records.push(...body.records);
  if (body.records.length < 100) break;
}
console.log(records.length);

Limits#

  • Only the first 10,000 matches can be paged through. A page that starts at or after record 10,001 answers 400. With 100 per page, the last page you can ask for is 100, so stop there in a loop over a large object.
  • To read more, split the query into smaller ones with filters, for example by ranges of createdAt dates.
  • There is no cursor pagination. If records are added, removed or reordered while you page, you can miss some or see one twice. Sorting by createdAt ascending keeps new records at the end. De-duplicate by id.