Pagination, filters and sorting

Pagination

Endpoints that return collections of resources must limit the number of records returned in a given response. The query parameter limit can be used to alter the number of records returned. A typical endpoint will return 15 records by default and will allow a maximum of 100 records to be returned. The query parameter offset can be used to offset the result set. These query parameters can be combined to recover all records in a collection through a series of requests by incrementing the offset by the value of limit with each request.

limitThe number of results to display in each page (default = 15; max = 100).
pageThe index of the current page of the results you expect to be returned. First index: 1. For example, if you query a set of 100 results and the limit is set to 15, page index 2 will return index 15 to 30.

Pagination Response

Below you will find a very basic pagination response example.

//campaigns?page=1&limit=15

{
   "total": 60,
   "per_page": 15,
   "current_page": 1,
   "last_page": 4,
   "first_page_url": "<<rootURL>>?page=1",
   "last_page_url": "<<rootURL>>?page=4",
   "next_page_url": "<<rootURL>>?page=2",
   "prev_page_url": null,
   "path": "http://someEndpoint.app",
   "from": 1,
   "to": 15,
   "data":[
        {
            // Result Object e.g. campaign
        },
        {
            // Result Object e.g. campaign
        }
   ]
}

Filters

The filters query parameter is available to apply multiple, convention oriented filters to a request. The parameter is set as an array where the key is the field to be filtered by and the value is the value to filter by. Not all fields are available for filtering in this way. Field filters will match on “equals” or “contains” on a case by case basis, as configured in the API endpoint. In the example below the results are filtered to campaigns where the status is completed and the name contains "test".

Response with filters

//campaigns?page=1&limit=20&filter[q]=test

{
   "current_page":1,
   "data":[
      {
         "hashed_id": "xxxxxxxxxxxxxxxxxx",
         "hashed_email_send_from_id":"xxxxxxxxxxxxxxxxxx",
         "hashed_email_reply_to_id":"xxxxxxxxxxxxxxxxxx",
         "hashed_list_id":"xxxxxxxxxxxxxxxxxx",
         "name":"Statistics test",
         "from_name":"Company B.V.",
         "subject":"Last chance: Up to 50% off selected AMF Fashion items",
         "preheader":"It's Black Friday! This is your last chance to save up to 50% on selected AMF Fashion items"
         "status":"completed",
        ...,
         "mailing_list":{
            "hashed_id":"xxxxxxxxxxxxxxxxxx",
            ...
         }
      },
      {
        ...
      },
   ],
   "first_page_url":"<<rootURL>>campaigns?page=1",
   "from":1,
   "last_page":1,
   "last_page_url":"<<rootURL>>campaigns?page=1",
   "links":[
      {
         "url":null,
         "label":"&laquo; Vorige",
         "active":false
      },
      {
         "url":"<<rootURL>>campaigns?page=1",
         "label":"1",
         "active":true
      },
      {
         "url":null,
         "label":"Volgende &raquo;",
         "active":false
      }
   ],
   "next_page_url":null,
   "path":"<<rootURL>>campaigns",
   "per_page":20,
   "prev_page_url":null,
   "to":20,
   "total":60
}

Sorting

The sort parameter is available to apply multiple sorting criteria to a request. The parameter is set as an array where the key is the field to be sorted by and the value is the direction of sort, either - (for descending) or + (for ascending, not required). Not all fields are available for ordering. The order in which sorting criteria is applied reflects the order in which the parameters are set in the query string.

In the example below the results are first sorted by the contacts email address descending, and then sorted by the contacts age, ascending.

// GET /campaigns?sort=-email,age