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.
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.
The following request fetches an SKU code and name, and the formatted amount of the related prices:
curl -X GET \https://yourdomain.commercelayer.io/api/skus/xYZkjABcde?include=prices&fields[skus]=code,name&fields[prices]=formatted_amount \-H 'Accept: application/vnd.api+json' \-H 'Authorization: Bearer your-access-token'
On success, the API responds with a 200 OK
status code, returning the requested fieldset:
{"data": {"id": "xYZkjABcde","type": "skus","links": {...},"attributes": {"code": "TSHIRTMM000000FFFFFFXLXX","name": "Black Men T-shirt with White Logo (XL)"},"relationships": {"shipping_category": {"links": {...}},"prices": {"links": {...},"data": [{"type": "prices","id": "yzkWXfgHQS"}]},"stock_items": {"links": {...}},"delivery_lead_times": {"links": {...}}},"meta": {"mode": "test"}},"included": [{"data": {"id": "yzkWXfgHQS","type": "prices","links": {...},"attributes": {"formatted_amount": "€100,00"},"relationships": {"price_list": {"links": {...}},"sku": {"links": {...}}},"meta": {...}}}]}