# Expanding

Source: https://developers.swell.is/backend-api/querying/expanding

Expanding allows you to include related records as defined by `link` or `collection` fields. For example, in [the cart model](https://developers.swell.is/backend-api/carts/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.

## Example request

**Example query using expand**

**cURL**

```bash
$ curl https://api.swell.store/carts/5407e0929fe97f9d4c712a5e?expand=items.product,items.variant
  -u store-id:secret-key
```

**Node**

```javascript
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');

await swell.get('/carts/{id}', {
  id: '5407e0929fe97f9d4c712a5e',
  expand: [
    'items.product',
    'items.variant',
  ],
});
```

**PHP**

```php
<?php $swell = new \\Swell\\Client('store-id', 'secret-key');

$swell->get('/carts/{id}', [
  'id' => '5407e0929fe97f9d4c712a5e',
  'expand' => [
    'items.product',
    'items.variant'
  ]
]);
```

## Example response

```json
{
  "id": "5407e0929fe97f9d4c712a5e",
  "items": [
    {
      "id": "5407e0929fe97f9d4c712a5f",
      "product_id": "5407e0929fe97f9d4c712a5g",
      "product": {
        "name": "Example product",
        ...
      }
    },
    {...}
  ],
  ...
}
```
