API Reference
Sparse fieldsets
How to request the API to return only specific fields
When you fetch a resource or collection, you can request the API to return only specific fields, using the fields query parameter. This reduces the response payload, optimizing the performances. If you want the API to return also specific related resources data, they must be included and added to the fields list as well.
The value of the fields parameter must be a comma-separated list that refers to the name(s) of the fields to be returned. Pay attention to avoid whitespaces before or after each comma.

Examples

Requesting specific attributes only

Request
Response
The following request fetches an SKU code and name:
1
curl -g -X GET \
2
'https://yourdomain.commercelayer.io/api/skus/xYZkjABcde?fields[skus]=code,name' \
3
-H 'Accept: application/vnd.api+json' \
4
-H 'Authorization: Bearer your-access-token'
Copied!
On success, the API responds with a 200 OK status code, returning the requested fieldset:
1
{
2
"data": {
3
"id": "xYZkjABcde",
4
"type": "skus",
5
"links": {...},
6
"attributes": {
7
"code": "TSHIRTMM000000FFFFFFXLXX",
8
"name": "Black Men T-shirt with White Logo (XL)"
9
},
10
"meta": {...}
11
}
12
}
Copied!
Request
Response
The following request fetches an SKU code, name, and related prices plus the formatted amount and the related price lists of each price:
1
curl -g -X GET \
2
'https://yourdomain.commercelayer.io/api/skus/xYZkjABcde?include=prices,prices.price_list&fields[skus]=code,name,prices&fields[prices]=formatted_amount,price_list' \
3
-H 'Accept: application/vnd.api+json' \
4
-H 'Authorization: Bearer your-access-token'
Copied!
On success, the API responds with a 200 OK status code, returning the requested fieldset:
1
{
2
"data": {
3
"id": "xYZkjABcde",
4
"type": "skus",
5
"links": {...},
6
"attributes": {
7
"code": "TSHIRTMM000000FFFFFFXLXX",
8
"name": "Black Men T-shirt with White Logo (XL)"
9
},
10
"relationships": {
11
"prices": {
12
"links": {...},
13
"data": [
14
{
15
"type": "prices",
16
"id": "ajKQUMdKQp"
17
},
18
{
19
"type": "prices",
20
"id": "AKeQUowyYa"
21
}
22
]
23
}
24
},
25
"meta": {...}
26
},
27
"included": [
28
{
29
"id": "ajKQUMdKQp",
30
"type": "prices",
31
"links": {...},
32
"attributes": {
33
"formatted_amount": "€100,00"
34
},
35
"relationships": {
36
"price_list": {
37
"links": {...},
38
"data": {
39
"type": "price_lists",
40
"id": "xlqjNCaKLw"
41
}
42
}
43
},
44
"meta": {...}
45
},
46
{
47
"id": "AKeQUowyYa",
48
"type": "prices",
49
"links": {...},
50
"attributes": {
51
"formatted_amount": "$124.80"
52
},
53
"relationships": {
54
"price_list": {
55
"links": {...},
56
"data": {
57
"type": "price_lists",
58
"id": "vLrWRCJWBE"
59
}
60
}
61
},
62
"meta": {...}
63
},
64
{
65
"id": "xlqjNCaKLw",
66
"type": "price_lists",
67
"links": {...},
68
"attributes": {
69
"name": "EUR Price List",
70
"currency_code": "EUR",
71
"tax_included": true,
72
"created_at": "2018-01-01T12:00:00.000Z",
73
"updated_at": "2018-01-01T12:00:00.000Z",
74
"reference": null,
75
"reference_origin": null,
76
"metadata": {}
77
},
78
"relationships": {
79
"prices": {
80
"links": {...}
81
},
82
"attachments": {
83
"links": {...}
84
}
85
},
86
"meta": {...}
87
},
88
{
89
"id": "vLrWRCJWBE",
90
"type": "price_lists",
91
"links": {...},
92
"attributes": {
93
"name": "USD Price List",
94
"currency_code": "USD",
95
"tax_included": false,
96
"created_at": "2018-01-01T12:00:00.000Z",
97
"updated_at": "2018-01-01T12:00:00.000Z",
98
"reference": null,
99
"reference_origin": null,
100
"metadata": {}
101
},
102
"relationships": {
103
"prices": {
104
"links": {...}
105
},
106
"attachments": {
107
"links": {...}
108
}
109
},
110
"meta": {...}
111
}
112
]
113
}
Copied!
You can request sparse fieldsets also when creating or updating resources.
Last modified 1mo ago
Copy link
Contents
Examples