Pagination

In this guide, we will look at how to work with paginated responses when querying the OneSend API. By default, all responses limit results to 30. If you are using one of the official OneSend API client libraries, you don't need to worry about pagination, as it's all being taken care of behind the scenes.

When an API response returns a list of objects, no matter the amount, pagination is supported. The paginated data is returned in the Hydra collection format, meaning the items you requested will be in the hydra:member property, while the hydra:view property will contain information about next (hydra:next), previous (hydra:previous), first (hydra:first) and last (hydra:last) pages.

Here is an example of a paginated response:

{
    "@context": "/contexts/MsisdnBlock",
    "@id": "/api/msisdn_blocks",
    "@type": "hydra:Collection",
    "hydra:member": [
        {
            "@id": "/msisdn_blocks/3fa85f64-5717-4562-b3fc-2c963f66afa6",
            "@type": "MsisdnBlock",
            "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
            "createdAt": "2024-02-20T15:42:00.626Z",
            "msisdn":"+491573123123123",
            "reason": "Complains too much"
        },
        {
            "_": "Other items in the collection..."
        },
    ],
    "hydra:totalItems": 90,
    "hydra:view": {
        "@id": "/api/msisdn_blocks?page=2",
        "@type": "hydra:PartialCollectionView",
        "hydra:first": "/api/msisdn_blocks?page=1",
        "hydra:previous": "/api/msisdn_blocks?page=1",
        "hydra:last": "/api/msisdn_blocks?page=3",
        "hydra:next": "/api/msisdn_blocks?page=3"
    }
}

Using this structure you can easily navigate the collection by just calling the respective URL as described by the hydra:view property.

Was this page helpful?