Line Items

Create a line item if you want to add an SKU to an order. Other types of line items are automatically created to add a shipping cost to the order or to apply a discount. The sum of all line item amounts makes the order's total, split into subtotal, taxes, and discount. The order object includes all the data you need. You never need to make any calculation on your application.

The line item object

A line item object is returned as part of the response body of each successful create, list, retrieve or update API call. The following table contains the list of all its fields along with their type, description and example values.
Object fields:
sku_code
string
The code of the associated sku
Example:
TSHIRTMM000000FFFFFFXLXX
quantity
integer
The line item quantity
Example:
2
currency_code
string
The international 3-letter currency code as defined by the ISO 4217 standard, automatically inherited from the order's market.
Example:
EUR
unit_amount_cents
integer
The unit amount of the line item, in cents. When you add a line item to an order, this is automatically populated from the price list associated to the order's market.
Example:
9900
unit_amount_float
float
The unit amount of the line item, float. This can be useful to track the purchase on thrid party systems, e.g Google Analyitcs Enhanced Ecommerce.
Example:
99.0
formatted_unit_amount
string
The unit amount of the line item, formatted. This can be useful to display the amount with currency in you views.
Example:
€99,00
options_amount_cents
integer
The options amount of the line item, in cents.
Example:
990
options_amount_float
float
The options amount of the line item, float.
Example:
9.9
formatted_options_amount
string
The options amount of the line item, formatted.
Example:
€9,90
total_amount_cents
integer
Calculated as unit amount x quantity + options amount, in cents.
Example:
18800
total_amount_float
float
Calculated as unit amount x quantity + options amount, float. This can be useful to track the purchase on thrid party systems, e.g Google Analyitcs Enhanced Ecommerce.
Example:
188.0
formatted_total_amount
string
Calculated as unit amount x quantity + options amount, formatted. This can be useful to display the amount with currency in you views.
Example:
€188,00
name
string
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)
image_url
string
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
tax_rate
float
The tax rate for this line item (if calculated).
Example:
0.22
tax_breakdown
object
The tax breakdown for this line item (if calculated).
Example:
{"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
string
The type of the associate item. Can be one of 'sku', 'shipment', 'payment_method' or 'promotion'
Example:
sku
id
integer
Unique identifier for the resource.
Example:
1234
created_at
datetime
Time at which the resource was created.
Example:
2018-01-01T12:00:00.000Z
updated_at
datetime
Time at which the resource was last updated.
Example:
2018-01-01T12:00:00.000Z
reference
string
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.
Example:
ANYREFEFERNCE
metadata
object
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.
Example:
{"foo":"bar"}
relationship (N:1)
The associated order.
item
relationship (N:1)
The polymorphic item associated to the line item. Can be a sku, a shipment, a payment_method or a promotion.
relationship (1:N)
The associated line item options.

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:
sku_code
optional
The code of the associated sku
Example:
TSHIRTMM000000FFFFFFXLXX
quantity
required
The line item quantity
Example:
2
_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.
Example:
1
name
optional
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)
image_url
optional
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
reference
optional
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.
Example:
ANYREFEFERNCE
metadata
optional
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.
Example:
#
required
The associated order.
item
optional
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"
    }
  }
}

List all line items

To fetch a collection of line items, send a GET request to the /api/line_items endpoint.

Example request:
GET /api/line_items HTTP/1.1
Accept: application/vnd.api+json
Example response: 200 OK
HTTP/1.1 200 OK
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"
      }
    },
    {
      "other": "... 24 line_items (first page)"
    }
  ],
  "meta": {
    "record_count": 125,
    "page_count": 5
  },
  "links": {
    "first": "/api/line_items?page[number]=1&page[size]=25",
    "prev": "/api/line_items?page[number]=2&page[size]=25",
    "next": "/api/line_items?page[number]=4&page[size]=25",
    "last": "/api/line_items?page[number]=5&page[size]=25"
  }
}
Available filters
idtotal_amount_centsitem_typereferenceorder_ididscreated_at_fromcreated_at_toupdated_at_fromupdated_at_to
Sortable attributes
total_amount_centsitem_typeidcreated_atupdated_atreference

Retrieve a line item

To fetch a single line item, send a GET request to the /api/line_items/{{id}} endpoint, where {{id}} is the id of the resource that you want to retrieve.
Example request:
GET /api/line_items/1234 HTTP/1.1
Accept: application/vnd.api+json
Example response: 200 OK
HTTP/1.1 200 OK
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"
    }
  }
}

Update a line item

To update an existing line item, send a PATCH request to the /api/line_items/{{id}} endpoint, where {{id}} is the id of the resource that you want to update. The following table contains the list of all the possible arguments that you can pass with the request body, along with their type, description and examples values. Please note that all arguments are optional.
Arguments:
sku_code
optional
The code of the associated sku
Example:
TSHIRTMM000000FFFFFFXLXX
quantity
optional
The line item quantity
Example:
2
name
optional
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)
image_url
optional
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
reference
optional
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.
Example:
ANYREFEFERNCE
metadata
optional
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.
Example:
#
Example request:
PATCH /api/line_items/1234 HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json

{
  "data": {
    "type": "line_items",
    "id": 1234,
    "attributes": {
      "sku_code": "TSHIRTMM000000FFFFFFXLXX"
    },
    "relationships": {
    }
  }
}
Example response: 200 OK
HTTP/1.1 200 OK
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"
    }
  }
}

Delete a line item

To delete a line item, send a DELETE request to the /api/line_items/{{id}} endpoint, where {{id}} is the id of the resource that you want to delete.
Example request:
DELETE /api/line_items/1234 HTTP/1.1
Accept: application/vnd.api+json
Example response: 204 No Content
HTTP/1.1 204 No Content

Get our machine-readable JSON schema that follows the OpenAPI Specification (formerly Swagger).

Get our Postman collection in one click and start making real calls to Commerce Layer API in minutes.

Get in touch with our support team if you have any questions or want to learn more about Commerce Layer.