Skip to main content

REST pagination

REST lists are paginated by offset, with the limit and offset parameters.

Parameters​

ParameterTypeDefaultDescription
limitint100Maximum number of items to return
offsetint0Number of items to skip from the beginning

Response structure​

{
"items": [...],
"count": 1250
}
  • items: the items of the page
  • count: the total number of results, regardless of limit and offset

Example​

First page (20 items):

curl -H "Authorization: Bearer YOUR_TOKEN" \
"https://core.riseact.org/api/v1/supporters/?limit=20&offset=0"

Second page:

curl -H "Authorization: Bearer YOUR_TOKEN" \
"https://core.riseact.org/api/v1/supporters/?limit=20&offset=20"

Response:

{
"items": [
{
"id": 1,
"first_name": "Mario",
"last_name": "Rossi",
"email": "mario@example.com"
}
],
"count": 1250
}

Computing the number of pages​

const totalPages = Math.ceil(response.count / limit);

Fetching all items​

async function fetchAll(endpoint, token) {
const limit = 100;
let offset = 0;
const results = [];

while (true) {
const res = await fetch(
`https://core.riseact.org/api/v1/${endpoint}/?limit=${limit}&offset=${offset}`,
{ headers: { Authorization: `Bearer ${token}` } }
);
const { items, count } = await res.json();

results.push(...items);
offset += limit;

if (offset >= count) break;
}

return results;
}

Ordering​

The order parameter sets the ordering field; the - prefix makes it descending. The default is -create_date, most recent first.

# Donations ordered by date ascending
GET /api/v1/donations/?order=create_date

# Donations ordered by date descending (default)
GET /api/v1/donations/?order=-create_date

Endpoints that support pagination​

EndpointMethod
/api/v1/supporters/GET
/api/v1/donations/GET
/api/v1/payments/GET
/api/v1/campaigns/GET
/api/v1/checkouts/GET