# Split by line items

## Problem

You have an order containing several SKUs, whose stock is available in different locations and — possibly — belongs to multiple shipping categories. You want to create at least a separate shipment per each line item of the order.

![The order is split into as many shipments as order's line items](https://2610849379-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lk-ezuDClaMavTqnRi0%2Fuploads%2FQSes5zZJCdQGNgnyE50f%2Fsplit-by-line-items.jpg?alt=media\&token=e94b7011-b807-41fa-9c63-49acd6694da4)

## Solution

You need to use the **split by line items** strategy. To do that, check the related option in the admin UI or send a `PATCH` request to the `inventory_models/:id` endpoint, setting the strategy attribute accordingly.

### Example

{% tabs %}
{% tab title="Request" %}
The following request explicitly updates the strategy for the inventory model identified by the "BwAezhyOQw" ID:

```javascript
curl -g -X PATCH \
  'http://yourdomain.commercelayer.io/api/inventory_models/BwAezhyOQw' \
  -H 'Accept: application/vnd.api+json' \
  -H 'Authorization: Bearer your-access-token' \
  -H 'Content-Type: application/vnd.api+json' \
  -d '{
  "data": {
    "type": "inventory_modeld",
    "id": "BwAezhyOQw",
    "attributes": {
      "strategy": "split_by_line_items"
    }
  }
}'
```

{% endtab %}

{% tab title="Response" %}
On success, the API responds with a `200 OK` status code, returning the updated inventory model object:

```javascript
{
  "data": {
    "id": "BwAezhyOQw",
    "type": "inventory_models",
    "links": {
      "self": "https://yourdomain.commercelayer.io/api/inventory_models/BwAezhyOQw"
    },
    "attributes": {
      "name": "EU Inventory Model",
      "strategy": "split_by_line_items",
      "stock_locations_cutoff": 3,
      "created_at": "2018-01-01T12:00:00.000Z",
      "updated_at": "2018-01-01T12:00:00.000Z",
      "reference": "ANY-EXTERNAL-REFEFERNCE",
      "reference_origin": "ANY-EXTERNAL-REFEFERNCE-ORIGIN",
      "metadata": {
        "foo": "bar"
      }
    },
    "relationships": {
      "inventory_stock_locations": {
        "links": {
          "self": "https://yourdomain.commercelayer.io/api/inventory_models/xYZkjABcde/relationships/inventory_stock_locations",
          "related": "https://yourdomain.commercelayer.io/api/inventory_models/xYZkjABcde/inventory_stock_locations"
        }
      },
      "inventory_return_locations": {
        "links": {
          "self": "https://yourdomain.commercelayer.io/api/inventory_models/xYZkjABcde/relationships/inventory_return_locations",
          "related": "https://yourdomain.commercelayer.io/api/inventory_models/xYZkjABcde/inventory_return_locations"
        }
      },
      "attachments": {
        "links": {
          "self": "https://yourdomain.commercelayer.io/api/inventory_models/xYZkjABcde/relationships/attachments",
          "related": "https://yourdomain.commercelayer.io/api/inventory_models/xYZkjABcde/attachments"
        }
      }
    },
    "meta": {
      "mode": "test"
    }
  }
}
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
This strategy works for line items of type `skus` **only**. If an order contains line items of type `bundles`, all the shipments and stock are managed by using the [split shipment](https://docs.commercelayer.io/how-tos/inventory/strategies/split-shipments) strategy as a fallback.
{% endhint %}

## How it works

This inventory strategy affects the creation of the resources involved in the process by the following logic.

#### Shipments

Each line item of the order generates at least a separate shipment, if possible from the primary stock location. In case the primary stock location cannot fulfill the SKUs associated with the line item, one or more shipments are created from the secondary locations.

#### Stock line items

Each SKU associated with the order generates a stock line item that is also linked to the stock location from which its quantity will be fulfilled.

#### Shipping categories

In case the order contains SKUs belonging to different shipping categories, this strategy introduces no side effects, since each line item already generates a separate shipment.

## Additional notes

#### Do not ship SKU

If an SKU is marked with the `do_not_ship` flag, no shipment is generated for it. The necessary stock line items are created anyway.

{% hint style="info" %}
This option still tracks inventory.
{% endhint %}

#### Do not track SKU

If an SKU is marked with the `do_not_track` flag, stock line items are still created but they aren't associated with any stock item so that the stock isn't decremented/incremented on order placement/cancellation.

{% hint style="info" %}
This option still generates shipments.
{% endhint %}

## More to read

See our documentation if you need more information on how to [update an inventory model](https://app.gitbook.com/s/RWJeylueWkzLadK710XZ/inventory_models/update) or if you want more information about [SKUs](https://app.gitbook.com/s/RWJeylueWkzLadK710XZ/skus), [shipments](https://app.gitbook.com/s/RWJeylueWkzLadK710XZ/shipments), [stock transfers](https://app.gitbook.com/s/RWJeylueWkzLadK710XZ/stock_transfers), and [stock line items](https://app.gitbook.com/s/RWJeylueWkzLadK710XZ/stock_line_items).
