Update a line item
How to update an existing line item via API
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.
Here below the list of all the possible arguments that you can pass with the request body.
Request
PATCH https://yourdomain.commercelayer.io/api/line_items/:id
Arguments
type
string
Required
id
string
Required
attributes.sku_code
string
Optional
attributes.bundle_code
string
Optional
attributes.quantity
integer
Optional
attributes._external_price
boolean
Optional
attributes._reserve_stock
boolean
Optional
attributes.unit_amount_cents
integer
Optional
attributes.compare_at_amount_cents
integer
Optional
attributes.options_amount_cents
integer
Optional
attributes.name
string
Optional
attributes.image_url
string
Optional
attributes.frequency
string
Optional
attributes._reset_circuit
boolean
Optional
attributes.reference
string
Optional
attributes.reference_origin
string
Optional
attributes.metadata
object
Optional
relationships.tags
array
Optional
Example
The following request updates the line item identified by the ID "xYZkjABcde":
curl -g -X PATCH \
'https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde' \
-H 'Accept: application/vnd.api+json' \
-H 'Authorization: Bearer your-access-token' \
-H 'Content-Type: application/vnd.api+json' \
-d '{
"data": {
"type": "line_items",
"id": "xYZkjABcde",
"attributes": {
"sku_code": "TSHIRTMM000000FFFFFFXLXX"
},
"relationships": {
"tags": {
"data": {
"type": "tags",
"id": "ABCRtyUpBa"
}
}
}
}
}'
On success, the API responds with a 200 OK
status code, returning the updated 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,
"_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",
"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"
}
},
"adjustment": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/relationships/adjustment",
"related": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/adjustment"
}
},
"gift_card": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/relationships/gift_card",
"related": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/gift_card"
}
},
"shipment": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/relationships/shipment",
"related": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/shipment"
}
},
"payment_method": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/relationships/payment_method",
"related": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/payment_method"
}
},
"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"
}
},
"return_line_items": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/relationships/return_line_items",
"related": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/return_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"
}
},
"notifications": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/relationships/notifications",
"related": "https://yourdomain.commercelayer.io/api/line_items/xYZkjABcde/notifications"
}
},
"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",
"organization_id": "xRRkjDFafe",
"trace_id": "69abaa3545913c78132e5578bd26208d44aa9043647d78698fd0021f3958cd74"
}
}
}
Last updated