Queries

Paging

When the result of some API methods is being displayed, it is necessary to use the paging parameter. In order to page results, you need to use two parameters in the Query String _offset and _limit, as the following examples show: https://api.viavarejo.com/api/v2/orders/status/new?_offset=0&_limit=100 As a result, a list with 100 objects from its first object is expected to return.

_offset: Indicates the initial position of the query. In other words, 100 indicates that the first register must be in the position #100.
_limit: Indicates the quantity of registers that the query must contain.

Note: the lists index starts with 0 (zero). That is, for a query with the 10 first items of a list (_offset=0 and _limit=10), the indexes will be from zero (0) to nine (9).

IMPORTANT NOTE:
In order to get a good integration performance, we recommend that the quantity of requested registers (_limit parameter) does not exceed 100 in the products queries (GET /sellerItems, GET /sellerItems/status/selling and GET /products), and 50 in the orders queries (all the orders queries by status, for example GET /orders/status/new). If the value is higher than the recommended, the services will overwrite the requested value with the limit value for every type of query.

Selection of attributes

In order to improve your experience with the API, now you can select the attributes that should be returned in the queries (GET methods). Consequently, it’s possible to reduce the quantity of information transmitted in the services, and you may search only for the most relevant information for your solution. Here is an example of how to use this resource: https://api.viavarejo.com/api/v2/orders/status/approved?_offset=0&_limit=100&attributes=id,purchasedAt,approvedAt,totalAmount This content will return a list of orders, and each item will have only the requested attributes, as the following:

[
    {
       "id" : "123321009",
       "purchasedAt" : "2014-08-01T08:54:00.000-03:00",
       "approvedAt" : "2014-08-01T08:59:10.000-03:00",
       "totalAmount" : "115.00"
    },
    {...}
]

Queries metadata

The queries metadata are information provided in order to help your application to page the obtained results. This information is returned in all the listing queries. You will see the object name and format below:

"metadata": [
    { "key": "", "value": "" },
]

We choose this format because it’s possible to add more useful information of the query later, without breaking the signature, since it’s about a map with a key/value. Here is an example of how this metadata is returned: Service: GET /orders/status/sent?_offset=0&_limit=100

{
    "orders": [
        {..}, {..}, ... {..}
    ],
    "metadata": [
        { "key": "totalRows", "value": "259" },
        { "key": "offset", "value": "0" },
        { "key": "limit", "value": "50" },
        { "key": "first", "value": "/orders/status/sent?_offset=0&_limit=50" },
        { "key": "previous", "value": "" },
        { "key": "next", "value": "/orders/status/sent?_offset=100&_limit=50" },
        { "key": "last", "value": "/orders/status/sent?_offset=250&_limit=50" }
    ]
}
IMPORTANT NOTE When your query is in the first or last page, the previous and next pages, respectively, will not be displayed. That is because when the current page is the first, there is no previous page, and the same happens to the last one, since there is no next page.
English