Commerce Layer will be proud to sponsor the next JAMstack Conf in London — 09-10 July, 2019 🎉 Stay tuned!

API REFERENCE

Sparse fieldsets

When you fetch a resource or collection, you can request the API to return only specific fields. This reduces the response payload, optimizing the performances. For example, the following request fetches an SKU code and name, and the formatted amount of the related prices.

GET /api/skus/1234?include=prices&fields[skus]=code,name&fields[prices]=formatted_amount HTTP/1.1
Accept: application/vnd.api+json
Note: you can request sparse fieldsets also when creating or updating resources.

On success, the API responds with a 200 OK status code, returning the requested fieldset:

HTTP/1.1 200 OK
Content-Type: application/vnd.api+json

{
  "data": {
    "id": "1234",
    "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": 1234
          }
        ]
      },
      "stock_items": {
        "links": {...}
      },
      "delivery_lead_times": {
        "links": {...}
      }
    },
    "meta": {
      "mode": "test"
    }
  },
  "included": [
    {
      "data": {
        "id": "1234",
        "type": "prices",
        "links": {...},
        "attributes": {
          "formatted_amount": "€100,00"
        },
        "relationships": {
          "price_list": {
            "links": {...}
          },
          "sku": {
            "links": {...}
          }
        },
        "meta": {...}
      }
    }
  ]
}

The value of the fields parameter MUST be a comma-separated list that refers to the name(s) of the fields to be returned.