Create a line item
To create a new line item, send a
POST
request to the
/api/line_items
endpoint, passing the resource arguments in the request body.
The following table contains the list of all the possible arguments, along with their type, description and examples values.
All the arguments marked as
required must be present in the request.
Arguments:
The code of the associated sku
Example:
TSHIRTMM000000FFFFFFXLXX
_update_quantity
optional
When creating a new line item, set this attribute to '1' if you want to update the line item quantity (if present) instead of creating a new line item for the same sku.
The name of the line item. When blank, it gets populated with the name of the associated item (if present).
Example:
Black Men T-shirt with White Logo (XL)
The image_url of the line item. When blank, it gets populated with the image_url of the associated item (if present, sku only).
Example:
https://img.yourbrand.com/skus/1234.png
A string that you can use to add your own identifier to the resource. This can be useful for intergrating the resource to an external system, like an ERP, a marketing tool or a CRM.
Set of key-value pairs that you can attach to the resource. This can be useful for storing additional information about the resource in a structured format.
The polymorphic item associated to the line item. Can be a sku, a shipment, a payment_method or a promotion.
Example request:
POST /api/line_items HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json
{
"data": {
"type": "line_items",
"attributes": {
"quantity": "2"
},
"relationships": {
"order": {
"data": {
"type": "orders",
"id": "1234"
}
}
}
}
}
Example response: 201 Created
HTTP/1.1 201 Created
Content-Type: application/vnd.api+json
{
"data": {
"id": "1234",
"type": "line_items",
"links": {
"self": "https://your-brand.commercelayer.io/api/line_items/1234"
},
"attributes": {
"sku_code": "TSHIRTMM000000FFFFFFXLXX",
"quantity": "2",
"currency_code": "EUR",
"unit_amount_cents": "9900",
"unit_amount_float": "99.0",
"formatted_unit_amount": "€99,00",
"options_amount_cents": "990",
"options_amount_float": "9.9",
"formatted_options_amount": "€9,90",
"total_amount_cents": "18800",
"total_amount_float": "188.0",
"formatted_total_amount": "€188,00",
"name": "Black Men T-shirt with White Logo (XL)",
"image_url": "https://img.yourbrand.com/skus/1234.png",
"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": "sku",
"id": "1234",
"created_at": "2018-01-01T12:00:00.000Z",
"updated_at": "2018-01-01T12:00:00.000Z",
"reference": "ANYREFEFERNCE",
"metadata": {
"foo": "bar"
}
},
"relationships": {
"order": {
"links": {
"self": "https://your-brand.commercelayer.io/api/line_items/1234/relationships/order",
"related": "https://your-brand.commercelayer.io/api/line_items/1234/order"
}
},
"item": {
"links": {
"self": "https://your-brand.commercelayer.io/api/line_items/1234/relationships/item",
"related": "https://your-brand.commercelayer.io/api/line_items/1234/item"
}
},
"line_item_options": {
"links": {
"self": "https://your-brand.commercelayer.io/api/line_items/1234/relationships/line_item_options",
"related": "https://your-brand.commercelayer.io/api/line_items/1234/line_item_options"
}
}
},
"meta": {
"mode": "test"
}
}
}