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.

Examples

Requesting specific attributes only

The following request fetches an SKU code and name:

curl -g -X GET \
  'https://yourdomain.commercelayer.io/api/skus/xYZkjABcde?fields[skus]=code,name' \
  -H 'Accept: application/vnd.api+json' \
  -H 'Authorization: Bearer your-access-token'

The following request fetches an SKU code, name, and related prices plus the formatted amount and the related price lists of each price:

curl -g -X GET \
  'https://yourdomain.commercelayer.io/api/skus/xYZkjABcde?fields[skus]=code,name,prices&fields[prices]=formatted_amount,price_list&include=prices.price_list' \
  -H 'Accept: application/vnd.api+json' \
  -H 'Authorization: Bearer your-access-token'

You can request sparse fieldsets also when creating or updating resources.

Last updated