Calling any list method that returns multiple results, such as /customers, may require pagination: multiple calls to fetch all the results. Metronome provides two URL parameters on most list endpoints for this purpose:
limit customizes how many results are returned per page
next_page specifies the cursor to use as a starting point to fetch the next set of results
When a returned response contains a next_page value, more records exist than were returned. Include that next_page value in a subsequent query to fetch the next set of results. To fetch every result, repeat this process until next_page is null.
GET /v1/customers?limit=10
{ "data": [ { "id": 1 }, { "id": 2 }, // ... ] // The next_page cursor that can be passed in the URL // to get the next set of results. "next_page": "0c34b75b47491b73db66d46737d9a87"}
Given the above response, you can provide the next_page cursor with the next request.
GET /v1/customers?limit=10&next_page=0c34b75b47491b73db66d46737d9a87
{ "data": [ { "id": 3 } ], // If no next_page value is returned, this is the last page of results. "next_page": null}
BEST PRACTICES FOR LIMITTo make a quick API call to inspect the response format, set limit=1. To load many results with as few API calls as possible, set limit=50. For performance reasons, limit is capped at 100.
Pagination in the request body
Some POST list endpoints read limit and next_page from the JSON request body instead of the URL. These include:
These endpoints ignore limit and next_page in the query string. They don’t return an error. Instead, they return the first page again, so a loop that passes the cursor in the URL never advances. Other POST list endpoints, such as /v1/contract-pricing/rate-cards/list, /v1/contract-pricing/products/list, and /v1/usage, take these values as URL parameters.
Pass the next_page value from the previous response in the request body, alongside the endpoint’s other fields. On these endpoints, limit is capped at 25.