Pagination

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

ParameterTypeDescription
pageintegerThe page to return, starting at 1. Defaults to 1.
per_pageintegerThe 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
  }
}
FieldDescription
pageThe current page.
per_pageRecords per page.
total_pagesThe total number of pages.
next_pageThe next page number, or null on the last page.
prev_pageThe previous page number, or null on the first page.
from / toThe positions of the first and last records on this page.
total_countThe 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;
}