Pagination

This guide uses the following placeholders for Datastore hostnames:

  • [dxp-hostname]: The hostname for your production or staging service in Squiz DXP (for example, au-123.datastore.squiz.cloud).

  • [sim-hostname]: The hostname for your local Datastore simulator (for example, localhost:7001).

Refer to Obtaining environment hostnames for instructions on obtaining your specific hostnames.

Paginating through a collection with the JavaScript SDK is straightforward.

Call limit() to set the page size, then fetch the next or previous page with getNextPage() and getPrevPage(). Use hasNextPage() and hasPrevPage() to determine whether additional pages are available.

However, requests are made when paginating directly by adding the page query variables page[size]=x, where x is a positive integer. It is also recommended that page[v]=2 is also passed to ensure you are using the most up-to-date pagination Datastore provides.

To make a pagination request using CURL:

curl \
    -X GET \
    -H "Content-Type: application/json" \
    --silent \
    -fS https://[dxp-hostname]/my-first-collection?page[size]=10&page[v]=2

The resulting paginated response looks like this:

{
    "data": [
        {
            "documentid": 1
        },
        {
            "documentid": 2
        },
        ...
        {
            "documentid": 10
        }
    ],
    "links": {
        "prev": null,
        "next": "/my-first-collection?page[size]=10&page[v]=2&page[after]=10"
    }
}

Pagination query parameters

Parameter Description

page[size]

The page size to be returned

page[v]

Pagination version to be used, default 1, recommended setting to 2 for enhanced pagination

page[after]

Token for the document to show pages after on subsequent requests. When null, there is no page after the current results

page[before]

Token for the document to show pages before on subsequent requests. When null, there is no page before the current results