Pagination

Fetching all objects of a resource can be convenient. At the same time returning too many objects at once can be unpractical from a performance perspective. Doing so might be too much work for the Mollie API to generate or for your website to process.

For this reason the Mollie API employs a Pagination Interface chopping the result of a certain API method call into pages you're able to programmatically scroll through. Using the count parameter you can select page size (up to a maximum of 250). The result will be paginated accordingly, presuming your request yields more than count objects. The offset parameter lets you skip a certain number of objects before your page starts.

In order to enable you to easily page through the result, every response links to the next, the previous, the first and the last page. This is an overview of all response fields:

Pagination parameters

totalCount
integer

The total number of objects available.

offset
integer

The number of skipped objects as requested.

count
integer

The number of objects found in data, which is either the requested number (with a maximum of 250) or the default number.

data
array

The actual data you're looking for.

links
object

Optional – Links to help navigate through the lists of objects, based on the given offset.

previous
string | null

Optional – The previous set of objects, if available.

next
string | null

Optional – The next set of objects, if available.

first
string | null

Optional – The first set of objects, if available.

last
string | null

Optional – The last set of objects, if available.

Example

In order to demo the Pagination Interface we use the Mollie API to fetch all of our payments.

Request code

require_once 'Mollie/API/Autoloader.php';

$mollie = new Mollie_API_Client;
$mollie->setApiKey('test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM');

$payments = $mollie->payments->all();

Response

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

{
    "totalCount": 280,
    "offset": 0,
    "count": 10,
    "data": [
        {
            "resource": "payment",
            "id": "tr_7UhSN1zuXS",
            "mode": "test",
            "createdDatetime": "2017-12-16T01:05:06.0Z",
            "status": "open",
            "expiryPeriod": "PT15M",
            "amount": 10.00,
            "description": "My first payment",
            "metadata": {
                "order_id": "12345"
            },
            "locale": "nl",
            "profileId": "pfl_QkEhN94Ba",
            "links": {
                "redirectUrl": "https://webshop.example.org/order/12345/"
            }
        },
        { ... },
        { ... }
    ],
    "links": {
        "first": "https://api.mollie.nl/v1/payments?count=10&offset=0",
        "previous": null,
        "next": "https://api.mollie.nl/v1/payments?count=10&offset=10",
        "last": "https://api.mollie.nl/v1/payments?count=10&offset=270"
    }
}