> For the complete documentation index, see [llms.txt](https://docs.commercelayer.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.commercelayer.io/core-api-reference/line_items/create.md).

# Create a line item

How to create a line item via API

To [create](https://docs.commercelayer.io/core/creating-resources) a new line item, send a `POST` request to the `/api/line_items` endpoint, passing the resource arguments in the request body.

## Request

**POST** <https://yourdomain.commercelayer.io/api/line\\_items>

### Arguments

| Body Parameter                              | Type      | Required                  |
| ------------------------------------------- | --------- | ------------------------- |
| **type**                                    | `string`  | Required                  |
| attributes.**sku\_code**                    | `string`  | Optional                  |
| attributes.**bundle\_code**                 | `string`  | Optional                  |
| attributes.**quantity**                     | `integer` | Required                  |
| attributes.**\_external\_price**            | `boolean` | Optional                  |
| attributes.**\_update\_quantity**           | `boolean` | Optional                  |
| attributes.**\_reserve\_stock**             | `boolean` | Optional                  |
| attributes.**\_reset\_restocked\_quantity** | `boolean` | Optional                  |
| attributes.**unit\_amount\_cents**          | `integer` | Required, unless computed |
| attributes.**compare\_at\_amount\_cents**   | `integer` | Optional                  |
| attributes.**name**                         | `string`  | Optional                  |
| attributes.**image\_url**                   | `string`  | Optional                  |
| attributes.**item\_type**                   | `string`  | Optional                  |
| attributes.**frequency**                    | `string`  | Optional                  |
| attributes.**reference**                    | `string`  | Optional                  |
| attributes.**reference\_origin**            | `string`  | Optional                  |
| attributes.**metadata**                     | `object`  | Optional                  |
| relationships.**order**                     | `object`  | Required                  |
| relationships.**item**                      | `object`  | Optional                  |
| relationships.**tags**                      | `array`   | Optional                  |

### Example

{% tabs %}
{% tab title="Request" %}
The following request creates a new line item:

```shell
curl -g -X POST \
  'https://yourdomain.commercelayer.io/api/line_items' \
  -H 'Accept: application/vnd.api+json' \
  -H 'Authorization: Bearer your-access-token' \
  -H 'Content-Type: application/vnd.api+json' \
  -d '{
  "data": {
    "type": "line_items",
    "attributes": {
      "sku_code": "TSHIRTMM000000FFFFFFXLXX",
      "quantity": 4
    }
  }
}'
```

{% endtab %}

{% tab title="Response" %}
On success, the API responds with a `201 Created` status code, returning the created resource object:

```json
{
  "data": {
    "id": "XAyRWNUzyN",
    "type": "line_items",
    "links": {
      "self": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN"
    },
    "attributes": {
      "sku_code": "TSHIRTMM000000FFFFFFXLXX",
      "bundle_code": "BUNDLEMM000000FFFFFFXLXX",
      "quantity": 4,
      "_external_price": true,
      "currency_code": "EUR",
      "unit_amount_cents": 10000,
      "unit_amount_float": 100.0,
      "formatted_unit_amount": "€100,00",
      "compare_at_amount_cents": 13000,
      "compare_at_amount_float": 130.0,
      "formatted_compare_at_amount": "€130,00",
      "options_amount_cents": 1000,
      "options_amount_float": 10.0,
      "formatted_options_amount": "€10,00",
      "discount_cents": -1000,
      "discount_float": 10.0,
      "formatted_discount": "€10,00",
      "total_amount_cents": 18800,
      "total_amount_float": 188.0,
      "formatted_total_amount": "€188,00",
      "tax_amount_cents": 1880,
      "tax_amount_float": 18.8,
      "formatted_tax_amount": "€18,80",
      "name": "Men's Black T-shirt with White Logo (XL)",
      "image_url": "https://img.yourdomain.com/skus/xYZkjABcde.png",
      "discount_breakdown": {
        "41": {
          "name": "10% ALL",
          "cents": -900,
          "weight": 0.416,
          "coupon_code": "XXXXXXXX"
        }
      },
      "tax_rate": 0.22,
      "tax_breakdown": {
        "id": "1234",
        "city_amount": "0.0",
        "state_amount": 6.6,
        "city_tax_rate": 0.0,
        "county_amount": 2.78,
        "taxable_amount": 139.0,
        "county_tax_rate": 0.02,
        "tax_collectable": 10.08,
        "special_tax_rate": 0.005,
        "combined_tax_rate": 0.0725,
        "city_taxable_amount": 0.0,
        "state_sales_tax_rate": 0.0475,
        "state_taxable_amount": 139.0,
        "county_taxable_amount": 139.0,
        "special_district_amount": 0.7,
        "special_district_taxable_amount": 139.0
      },
      "item_type": "skus",
      "frequency": "monthly",
      "coupon_code": "SUMMERDISCOUNT",
      "rule_outcomes": [],
      "circuit_state": "closed",
      "circuit_failure_count": 5,
      "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": {
      "order": {
        "links": {
          "self": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/relationships/order",
          "related": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/order"
        }
      },
      "item": {
        "links": {
          "self": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/relationships/item",
          "related": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/item"
        }
      },
      "sku": {
        "links": {
          "self": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/relationships/sku",
          "related": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/sku"
        }
      },
      "bundle": {
        "links": {
          "self": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/relationships/bundle",
          "related": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/bundle"
        }
      },
      "adjustment": {
        "links": {
          "self": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/relationships/adjustment",
          "related": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/adjustment"
        }
      },
      "gift_card": {
        "links": {
          "self": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/relationships/gift_card",
          "related": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/gift_card"
        }
      },
      "shipment": {
        "links": {
          "self": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/relationships/shipment",
          "related": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/shipment"
        }
      },
      "payment_method": {
        "links": {
          "self": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/relationships/payment_method",
          "related": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/payment_method"
        }
      },
      "line_item_options": {
        "links": {
          "self": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/relationships/line_item_options",
          "related": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/line_item_options"
        }
      },
      "return_line_items": {
        "links": {
          "self": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/relationships/return_line_items",
          "related": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/return_line_items"
        }
      },
      "shipment_line_items": {
        "links": {
          "self": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/relationships/shipment_line_items",
          "related": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/shipment_line_items"
        }
      },
      "stock_reservations": {
        "links": {
          "self": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/relationships/stock_reservations",
          "related": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/stock_reservations"
        }
      },
      "stock_line_items": {
        "links": {
          "self": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/relationships/stock_line_items",
          "related": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/stock_line_items"
        }
      },
      "stock_transfers": {
        "links": {
          "self": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/relationships/stock_transfers",
          "related": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/stock_transfers"
        }
      },
      "attachments": {
        "links": {
          "self": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/relationships/attachments",
          "related": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/attachments"
        }
      },
      "notifications": {
        "links": {
          "self": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/relationships/notifications",
          "related": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/notifications"
        }
      },
      "events": {
        "links": {
          "self": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/relationships/events",
          "related": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/events"
        }
      },
      "tags": {
        "links": {
          "self": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/relationships/tags",
          "related": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/tags"
        }
      },
      "event_stores": {
        "links": {
          "self": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/relationships/event_stores",
          "related": "https://yourdomain.commercelayer.io/api/line_items/XAyRWNUzyN/event_stores"
        }
      }
    },
    "meta": {
      "mode": "test",
      "organization_id": "xRRkjDFafe",
      "trace_id": "69abaa3545913c78132e5578bd26208d44aa9043647d78698fd0021f3958cd74"
    }
  },
  "meta": {
    "mode": "test",
    "organization_id": "xRRkjDFafe",
    "trace_id": "69abaa3545913c78132e5578bd26208d44aa9043647d78698fd0021f3958cd74"
  }
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.commercelayer.io/core-api-reference/line_items/create.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `build a script that syncs our docs to a CMS` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
