Backend API
Expanding allows you to include related records as defined by link or collection fields. For example, in the cart model, items are linked to a product with the product field which means they aren't automatically included in the result when retrieving a cart. Since the item product is nested in a list of objects, you would use dot-notation to specify the path to the expandable field.
When the expandable field refers to many records, you may want to specify a limit to include more than the default limit, which is 5. To do that for example, use the format variants:50 with the field name and limit separated by :.
When retrieving a list of results, expand will be performed on all records in the result set.
Expand paths can be at most 5 levels deep—deeper queries return an error.
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');
await swell.get('/carts/{id}', {
id: '5407e0929fe97f9d4c712a5e',
expand: [
'items.product',
'items.variant',
],
});
Response
{
"id": "5407e0929fe97f9d4c712a5e",
"items": [
{
"id": "5407e0929fe97f9d4c712a5f",
"product_id": "5407e0929fe97f9d4c712a5g",
"product": {
"name": "Example product",
...
}
},
{...}
],
...
}