Including associations
How to include a resource and its associations in the same request
Examples
Fetching an SKU and some of its associations
curl -g -X GET \
'https://yourdomain.commercelayer.io/api/skus/xYZkjABcde?include=prices,stock_items' \
-H 'Accept: application/vnd.api+json' \
-H 'Authorization: Bearer your-access-token'{
"data": {
"id": "xYZkjABcde",
"type": "skus",
"links": { ... },
"attributes": { ... },
"relationships": {
"shipping_category": { ... },
"prices": {
"links": { .. },
"data": [
{
"type": "prices",
"id": "pxEWUBWXLA"
}
]
},
"stock_items": {
"links": { ... },
"data": [
{
"type": "stock_items",
"id": "jAdEfdlvBK"
},
{
"type": "stock_items",
"id": "jpQRfJlrwN"
}
]
},
"stock_reservations": { ... },
"delivery_lead_times": { ... },
"sku_options": { ... },
"attachments": { ... },
"events": { ... },
"tags": { ... }
},
"meta": {
"mode": "test",
"organization_id": "EnAvaFOrRe"
}
},
"included": [
{
"id": "pxEWUBWXLA",
"type": "prices",
"links": { ... },
"attributes": {
"currency_code": "USD",
"sku_code": "TSHIRTMM000000FFFFFFMXXX",
"amount_cents": 3480,
"amount_float": 34.8,
"formatted_amount": "$34.80",
"compare_at_amount_cents": 4524,
"compare_at_amount_float": 45.24,
"formatted_compare_at_amount": "$45.24",
"created_at": "2019-05-14T10:36:53.987Z",
"updated_at": "2019-05-14T10:36:53.987Z",
"reference": null,
"reference_origin": null,
"metadata": {}
},
"relationships": {
"price_list": { ... },
"sku": { ... },
"price_tiers": { ... },
"price_volume_tiers": { ... },
"price_frequency_tiers": { ... },
"attachments": { ... }
},
"meta": {
"mode": "test",
"organization_id": "EnAvaFOrRe"
}
},
{
"id": "jAdEfdlvBK",
"type": "stock_items",
"links": { ... },
"attributes": {
"sku_code": "TSHIRTMM000000FFFFFFMXXX",
"quantity": 76,
"created_at": "2019-05-14T10:36:53.980Z",
"updated_at": "2019-05-14T10:36:53.980Z",
"reference": null,
"reference_origin": null,
"metadata": {}
},
"relationships": {
"stock_location": { ... },
"sku": { ... },
"reserved_stock": { ... },
"stock_reservations": { ... },
"attachments": { ... }
},
"meta": {
"mode": "test",
"organization_id": "EnAvaFOrRe"
}
},
{
"id": "jpQRfJlrwN",
"type": "stock_items",
"links": { ... },
"attributes": {
"sku_code": "TSHIRTMM000000FFFFFFMXXX",
"quantity": 28,
"created_at": "2019-05-14T10:36:53.993Z",
"updated_at": "2019-05-14T10:36:53.993Z",
"reference": null,
"reference_origin": null,
"metadata": {}
},
"relationships": {
"stock_location": { ... },
"sku": { ... },
"reserved_stock": { ... },
"stock_reservations": { ... },
"attachments": { ... }
},
"meta": {
"mode": "test",
"organization_id": "EnAvaFOrRe"
}
}
]
}Using relationship paths
curl -g -X GET \
'https://yourdomain.commercelayer.io/api/skus/xYZkjABcde?include=stock_items.reserved_stock' \
-H 'Accept: application/vnd.api+json' \
-H 'Authorization: Bearer your-access-token'{
"data": {
"id": "xYZkjABcde",
"type": "skus",
"links": { ... },
"attributes": { ... },
"relationships": {
"shipping_category": { ... },
"prices": { ... },
"stock_items": {
"links": { ... },
"data": [
{
"type": "stock_items",
"id": "jAdEfdlvBK"
},
{
"type": "stock_items",
"id": "jpQRfJlrwN"
}
]
},
"stock_reservations": { ... },
"delivery_lead_times": { ... },
"sku_options": { ... },
"attachments": { ... },
"events": { ... },
"tags": { ... }
},
"meta": {
"mode": "test",
"organization_id": "EnAvaFOrRe"
}
},
"included": [
{
"id": "jAdEfdlvBK",
"type": "stock_items",
"links": { ... },
"attributes": {
"sku_code": "TSHIRTMM000000FFFFFFMXXX",
"quantity": 76,
"created_at": "2019-05-14T10:36:53.980Z",
"updated_at": "2019-05-14T10:36:53.980Z",
"reference": null,
"reference_origin": null,
"metadata": {}
},
"relationships": {
"stock_location": { ... },
"sku": { ... },
"reserved_stock": {
"links": { ... },
"data": null
},
"stock_reservations": { ... },
"attachments": { ... }
},
"meta": {
"mode": "test",
"organization_id": "EnAvaFOrRe"
}
},
{
"id": "jpQRfJlrwN",
"type": "stock_items",
"links": { ... },
"attributes": {
"sku_code": "TSHIRTMM000000FFFFFFMXXX",
"quantity": 28,
"created_at": "2019-05-14T10:36:53.993Z",
"updated_at": "2019-05-14T10:36:53.993Z",
"reference": null,
"reference_origin": null,
"metadata": {}
},
"relationships": {
"stock_location": { ... },
"sku": { ... },
"reserved_stock": {
"links": { ... },
"data": {
"type": "reserved_stocks",
"id": "noJnMSBLXo"
}
},
"stock_reservations": { ... },
"attachments": { ... }
},
"meta": {
"mode": "test",
"organization_id": "EnAvaFOrRe"
}
},
{
"id": "noJnMSBLXo",
"type": "reserved_stocks",
"links": { ... },
"attributes": {
"quantity": 5,
"created_at": "2023-07-17T10:29:13.433Z",
"updated_at": "2023-07-17T10:29:13.441Z",
"reference": null,
"reference_origin": null,
"metadata": {}
},
"relationships": {
"stock_item": { ... },
"sku": { ... },
"stock_reservations": { ... },
"meta": {
"mode": "test",
"organization_id": "EnAvaFOrRe"
}
}
]
}Last updated