Fields¶
fields
is a parameter available on many endpoints, allowing you to
customize what data is included in the response.
There are two ways of referencing an index that is an array: By using
dot (“.”): fields=category.id,category.name
or by using parenthesis:
fields=category(id,name)
You can use any combination of them,
fields=category(id,name,products_total)
and
fields=category.id,category.name,category.products_total
are
equivalent.
Limit data¶
If you simply want to limit the output that you are fetching to minimize the bandwidth usage then simply specify the fields that you actually need.
GET /products/1732378
{
"id": 1732378,
"name": "Samsung Galaxy S4 LTE GT-i9505 16GB",
"popularity": 1,
"stock": {
"status": "in_stock"
},
"uri": ".../products/1732378",
"price": {
"regular": 5430,
"alternative": 5890,
"in_stock": 5430
},
...
}
If you set fields to id,name
, you will get a lot less data:
GET /products/1732378?fields=id,name
{
"id": 1732378,
"name": "Samsung Galaxy S4 LTE GT-i9505 16GB"
}
Example of referencing an array index:
GET /products/1732378?fields=id,name,price.regular
{
"id": 1732378,
"name": "Samsung Galaxy S4 LTE GT-i9505 16GB",
"price": {
"regular": 5430
}
}
Fetch more data¶
*
(asterisk/”star”) indicates “all standard data”.
For the product endpoint, category is a sub resource. We only fetch a
limited number of fields by default. If you want to fetch the whole
category you would use fields=category
. But, doing this means that
we are also saying we only want the category index. So, if you want all
the standard fields + all the category standard fields, you would write:
fields=*,category
.
GET /products/1732378?fields=*,category
{
"id": 1732378,
"name": "Samsung Galaxy S4 LTE GT-i9505 16GB",
...
"category": {
"id": "103",
"name": "Mobiltelefoner",
"uri": ".../categories/103",
"products_total": 541,
"lowest_price": 125,
"description": "text...",
"logo": "https://pricespy-75b8.kxcdn.com/g/cat/96/mobil.png",
"path": {
"103": "Mobiltelefoner",
"298": "Telefoni & GPS"
},
"parent": {
"id": "298"
}
},
...
}