Paging results

Overview

You can define the page size of the result list. There are 2 parameters: Limit and Offset. Both parameters define the size block of the results. This article is based on the search example, but you can use paging on every resource that presents on its response information about “paging”, like follows:

.....
  "paging": {
    "total": 285,
    "offset": 0,
    "limit": 50,
  }
  .....



range-slider

Contents:

  • Default values
  • Limit
  • Offset
  • Define a range of results

Default values

Default values are offset=0 and limit=50.

curl https://api.mercadolibre.com/sites/MLA/search?q=ipod nano



In the paging section of the JSON response, you can see the total number of items that match the search and the offset value with the default limit applied.

.....
  "paging": {
    "total": 285,
    "offset": 0,
    "limit": 50,
  }
  .....


Limit

To reduce the page size you can change the limit parameter. For example, if you are interested in retrieving just the first 3 items:

curl https://api.mercadolibre.com/sites/MLA/search?q=ipod nano&limit=3



This action retrieves a JSON data with an array of 3 items as shown:

{
  "site_id": "MLA",
  "query": "ipod nano",
  "paging": {
    "total": 284,
    "offset": 0,
    "limit": 3,
  },
  "results": [
    {...},
    {...},
    {...},
  ],
  "sort": {...},
  "available_sorts": [...],
  "filters": [...],
  "available_filters": [...],
}


Offset

By using the offset attribute, you can move the lower limit of the result block. For example, if you are interested in retrieving the 50 items that follow the default response:

curl https://api.mercadolibre.com/sites/MLA/search?q=ipod nano&offset=50
{
  "site_id": "MLA",
  "query": "ipod nano",
  "paging": {
    "total": 285,
    "offset": 50,
    "limit": 50,
  },
  "results": [...],
  "sort": {...},
  "available_sorts": [...],
  "filters": [...],
  "available_filters": [...],
}



This response retrieves 50 items starting from the first fifty items.

Define a range of results

It is possible to combine both parameters. You can retrieve items from the third to the sixth item in the original search result:

curl https://api.mercadolibre.com/sites/MLA/search?q=ipod nano&offset=3&limit=3



This action retrieves a JSON data with an array of 5 items as shown:

{
  "site_id": "MLA",
  "query": "ipod nano",
  "paging": {
    "total": 285,
    "offset": 3,
    "limit": 3,
  },
  "results": [
    {...},
    {...},
    {...},
  ],
  "sort": {...},
  "available_sorts": [...],
  "filters": [...],
  "available_filters": [...],
}


Please rate this