List endpoints such as GET /links, GET /payments and GET /recipients return results one page at a time. (GET /payouts is the exception: it returns all payouts in one response.)
Request parameters
| Parameter | Type | Description |
|---|---|---|
page | integer | The page to return, starting at 1. Defaults to 1. |
per_page | integer | The number of records per page. The default depends on the endpoint; see each endpoint's reference. |
Response
Every paginated response has a data array and a pagination_meta object:
{
"data": [ ... ],
"pagination_meta": {
"page": 2,
"per_page": 10,
"total_pages": 5,
"next_page": 3,
"prev_page": 1,
"from": 11,
"to": 20,
"total_count": 47
}
}| Field | Description |
|---|---|
page | The current page. |
per_page | Records per page. |
total_pages | The total number of pages. |
next_page | The next page number, or null on the last page. |
prev_page | The previous page number, or null on the first page. |
from / to | The positions of the first and last records on this page. |
total_count | The total number of records across all pages. |
Fetching every page
Keep requesting until next_page is null. Don't stop on an empty data array: asking for a page past the end can return the last page again.
async function fetchAll(path) {
const records = [];
let page = 1;
while (page) {
const res = await fetch(
`https://business.mamopay.com/manage_api/v1${path}?page=${page}&per_page=50`,
{ headers: { Authorization: `Bearer ${process.env.MAMO_API_KEY}` } }
);
const body = await res.json();
records.push(...body.data);
page = body.pagination_meta.next_page;
}
return records;
}