Create a line item
How to create a line item via API
To create a new line item, send a
POST
request to the /api/line_items
endpoint, passing the resource arguments in the request body.POST https://yourdomain.commercelayer.io/api/line_items
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.unit_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.sku | object | Optional |
relationships.bundle | object | Optional |
relationships.tags | array | Optional |
Request
Response
The following request creates a new line item:
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": {
"quantity": 4
},
"relationships": {
"order": {
"data": {
"type": "orders",
"id": "ABCRtyUpBa"
}
}
}
}
}'
On success, the API responds with a
201 Created
status code, returning the created resource object:{
"data": {
"id": "xYZkjABcde",
"type": "line_items",
"links": {
"self": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde"
},
"attributes": {
"sku_code": "TSHIRTMM000000FFFFFFXLXX",
"bundle_code": "BUNDLEMM000000FFFFFFXLXX",
"quantity": 4,
"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",
"discount_cents": -900,
"discount_float": 9.0,
"formatted_discount": "€9,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": "Black Men 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",
"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/xYZkjABcde/relationships/order",
"related": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/order"
}
},
"item": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/relationships/item",
"related": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/item"
}
},
"sku": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/relationships/sku",
"related": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/sku"
}
},
"bundle": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/relationships/bundle",
"related": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/bundle"
}
},
"line_item_options": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/relationships/line_item_options",
"related": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/line_item_options"
}
},
"shipment_line_items": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/relationships/shipment_line_items",
"related": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/shipment_line_items"
}
},
"stock_reservations": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/relationships/stock_reservations",
"related": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/stock_reservations"
}
},
"stock_line_items": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/relationships/stock_line_items",
"related": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/stock_line_items"
}
},
"stock_transfers": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/relationships/stock_transfers",
"related": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/stock_transfers"
}
},
"events": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/relationships/events",
"related": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/events"
}
},
"tags": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/relationships/tags",
"related": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/tags"
}
}
},
"meta": {
"mode": "test"
}
}
}
Last modified 1d ago