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.

Request

POST https://yourdomain.commercelayer.io/api/line_items

Arguments

Body ParameterTypeRequired

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

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.sku

object

Optional

relationships.bundle

object

Optional

relationships.adjustment

object

Optional

relationships.gift_card

object

Optional

relationships.shipment

object

Optional

relationships.payment_method

object

Optional

relationships.tags

array

Optional

Example

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,
      "unit_amount_cents": 10000
    },
    "relationships": {
      "order": {
        "data": {
          "type": "orders",
          "id": "ABCRtyUpBa"
        }
      }
    }
  }
}'

Last updated