Cart Management
Update Line Item
Updates the quantity of an existing line item in the shopping cart
PUT
/
api
/
v2
/
domains
/
{domain}
/
cart
/
line-items
/
{lineItemId}
Update Line Item
curl --request PUT \
--url https://api.firmly.work/api/v2/domains/{domain}/cart/line-items/{lineItemId} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"quantity": 123
}
'import requests
url = "https://api.firmly.work/api/v2/domains/{domain}/cart/line-items/{lineItemId}"
payload = { "quantity": 123 }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({quantity: 123})
};
fetch('https://api.firmly.work/api/v2/domains/{domain}/cart/line-items/{lineItemId}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.firmly.work/api/v2/domains/{domain}/cart/line-items/{lineItemId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'quantity' => 123
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.firmly.work/api/v2/domains/{domain}/cart/line-items/{lineItemId}"
payload := strings.NewReader("{\n \"quantity\": 123\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://api.firmly.work/api/v2/domains/{domain}/cart/line-items/{lineItemId}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"quantity\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.firmly.work/api/v2/domains/{domain}/cart/line-items/{lineItemId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"quantity\": 123\n}"
response = http.request(request)
puts response.read_body{
"cart_id": "cart_01H2XVBR8C8JS5MQSFPJ8HF9SA",
"platform_id": "shopify",
"shop_id": "staging.luma.gift",
"display_name": "Luma Store",
"cart_status": "active",
"line_items": [
{
"line_item_id": "item_01H2XVBR8C8JS5MQSFPJ8HF9SB",
"sku": "MH07-XS-Gray",
"variant_id": "MH07-XS-Gray",
"description": "Hero Hoodie - Gray XS",
"quantity": 2,
"price": {
"currency": "USD",
"value": 54.00,
"number": 5400,
"symbol": "$"
},
"line_price": {
"currency": "USD",
"value": 108.00,
"number": 10800,
"symbol": "$"
}
}
],
"shipments": [
{
"shipment_id": "ship_01H2XVBR8C8JS5MQSFPJ8HF9SC",
"line_item_ids": ["item_01H2XVBR8C8JS5MQSFPJ8HF9SB"],
"fulfillment_type": {
"id": "SHIP_TO_ADDRESS",
"name": "Ship to Address",
"description": "Standard shipping to customer address"
},
"shipping_method": {
"id": "STANDARD_GROUND",
"description": "Standard Ground Shipping",
"price": {
"currency": "USD",
"value": 49.99,
"number": 4999,
"symbol": "$"
},
"estimated_delivery": "5-7 business days"
}
}
],
"addons": {
"offers": [
{
"addon_id": "bulk_discount",
"display": {
"name": "Bulk Purchase Discount",
"description": "Save 5% on orders with 2+ items"
},
"scope": "CART",
"price": {
"currency": "USD",
"value": -130.00,
"number": -13000,
"symbol": "$"
}
}
],
"selections": []
},
"sub_total": {
"currency": "USD",
"value": 108.00,
"number": 10800,
"symbol": "$"
},
"shipping_total": {
"currency": "USD",
"value": 49.99,
"number": 4999,
"symbol": "$"
},
"tax_total": {
"currency": "USD",
"value": 10.80,
"number": 1080,
"symbol": "$"
},
"addon_total": {
"currency": "USD",
"value": 0.00,
"number": 0,
"symbol": "$"
},
"fees": [
{
"description": "Recycle fee",
"currency": "USD",
"value": 2.00,
"number": 200,
"symbol": "$"
}
],
"fee_total": {
"currency": "USD",
"value": 2.00,
"number": 200,
"symbol": "$"
},
"total": {
"currency": "USD",
"value": 170.79,
"number": 17079,
"symbol": "$"
},
"schema_version": "2.0"
}
Overview
The Update Line Item endpoint modifies the quantity of an existing product in the cart. Key features include:- Quantity Modification: Update item quantities or remove items by setting quantity to 0
- Automatic Recalculation: All pricing and shipment information is automatically updated
- Shipment Preservation: Items remain in their assigned shipments after quantity updates
- Addon Adjustment: Addon offers may change based on new cart totals
Authentication
Path Parameters
Request Body
Response
Returns the complete updated shopping cart. See Get Cart for full response schema.Update Behavior:
- Quantity > 0: Updates the item quantity and recalculates pricing
- Quantity = 0: Removes the item from the cart and its shipment
- Empty Shipments: Shipments with no remaining items are automatically removed
Code Examples
curl --request PUT \
--url https://api.firmly.work/api/v2/domains/staging.luma.gift/cart/line-items/item_01H2XVBR8C8JS5MQSFPJ8HF9SB \
--header 'Content-Type: application/json' \
--header 'x-firmly-authorization: YOUR_TOKEN' \
--data '{
"quantity": 2
}'
const response = await fetch('https://api.firmly.work/api/v2/domains/staging.luma.gift/cart/line-items/item_01H2XVBR8C8JS5MQSFPJ8HF9SB', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'x-firmly-authorization': 'YOUR_TOKEN'
},
body: JSON.stringify({
quantity: 2
})
});
const cart = await response.json();
console.log(cart);
import requests
response = requests.put(
'https://api.firmly.work/api/v2/domains/staging.luma.gift/cart/line-items/item_01H2XVBR8C8JS5MQSFPJ8HF9SB',
headers={
'Content-Type': 'application/json',
'x-firmly-authorization': 'YOUR_TOKEN'
},
json={
'quantity': 2
}
)
cart = response.json()
print(cart)
<?php
$curl = curl_init();
$data = [
'quantity' => 2
];
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.firmly.work/api/v2/domains/staging.luma.gift/cart/line-items/item_01H2XVBR8C8JS5MQSFPJ8HF9SB",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-firmly-authorization: YOUR_TOKEN"
],
CURLOPT_POSTFIELDS => json_encode($data)
]);
$response = curl_exec($curl);
curl_close($curl);
$cart = json_decode($response, true);
print_r($cart);
?>
Example Scenarios
Increase Quantity
Update an item from quantity 1 to 2:// Request
{
"quantity": 2
}
// Response shows updated quantity and recalculated totals
{
"line_items": [
{
"line_item_id": "item_01H2XVBR8C8JS5MQSFPJ8HF9SB",
"quantity": 2,
"price": {
"value": 54.00
},
"line_price": {
"value": 108.00
}
}
],
"sub_total": {
"value": 108.00
}
}
Remove Item
Set quantity to 0 to remove an item:// Request
{
"quantity": 0
}
// Response shows item removed from cart and shipments
{
"line_items": [],
"shipments": [],
"sub_total": {
"value": 0
}
}
{
"cart_id": "cart_01H2XVBR8C8JS5MQSFPJ8HF9SA",
"platform_id": "shopify",
"shop_id": "staging.luma.gift",
"display_name": "Luma Store",
"cart_status": "active",
"line_items": [
{
"line_item_id": "item_01H2XVBR8C8JS5MQSFPJ8HF9SB",
"sku": "MH07-XS-Gray",
"variant_id": "MH07-XS-Gray",
"description": "Hero Hoodie - Gray XS",
"quantity": 2,
"price": {
"currency": "USD",
"value": 54.00,
"number": 5400,
"symbol": "$"
},
"line_price": {
"currency": "USD",
"value": 108.00,
"number": 10800,
"symbol": "$"
}
}
],
"shipments": [
{
"shipment_id": "ship_01H2XVBR8C8JS5MQSFPJ8HF9SC",
"line_item_ids": ["item_01H2XVBR8C8JS5MQSFPJ8HF9SB"],
"fulfillment_type": {
"id": "SHIP_TO_ADDRESS",
"name": "Ship to Address",
"description": "Standard shipping to customer address"
},
"shipping_method": {
"id": "STANDARD_GROUND",
"description": "Standard Ground Shipping",
"price": {
"currency": "USD",
"value": 49.99,
"number": 4999,
"symbol": "$"
},
"estimated_delivery": "5-7 business days"
}
}
],
"addons": {
"offers": [
{
"addon_id": "bulk_discount",
"display": {
"name": "Bulk Purchase Discount",
"description": "Save 5% on orders with 2+ items"
},
"scope": "CART",
"price": {
"currency": "USD",
"value": -130.00,
"number": -13000,
"symbol": "$"
}
}
],
"selections": []
},
"sub_total": {
"currency": "USD",
"value": 108.00,
"number": 10800,
"symbol": "$"
},
"shipping_total": {
"currency": "USD",
"value": 49.99,
"number": 4999,
"symbol": "$"
},
"tax_total": {
"currency": "USD",
"value": 10.80,
"number": 1080,
"symbol": "$"
},
"addon_total": {
"currency": "USD",
"value": 0.00,
"number": 0,
"symbol": "$"
},
"fees": [
{
"description": "Recycle fee",
"currency": "USD",
"value": 2.00,
"number": 200,
"symbol": "$"
}
],
"fee_total": {
"currency": "USD",
"value": 2.00,
"number": 200,
"symbol": "$"
},
"total": {
"currency": "USD",
"value": 170.79,
"number": 17079,
"symbol": "$"
},
"schema_version": "2.0"
}
Error Responses
400 Bad Request
400 Bad Request
Invalid request format or parameters
{
"code": 400,
"error": "ErrorInvalidInputBody",
"description": "Invalid request format"
}
404 Not Found
404 Not Found
Line item does not exist in the cart
{
"code": 404,
"error": "ErrorLineItemNotFound",
"description": "Line item does not exist"
}
422 Unprocessable Entity
422 Unprocessable Entity
Invalid quantity or processing error
{
"code": 422,
"error": "ErrorInvalidQuantity",
"description": "Quantity must be non-negative"
}
Update Behavior
The Update Line Item endpoint maintains cart integrity:
- Shipment Assignment: Items remain in their assigned shipments after updates
- Empty Shipment Cleanup: Shipments with no items are automatically removed
- Addon Recalculation: Available addons may change based on new cart value
- Price Updates: All totals are recalculated including shipping and tax
Implementation Notes
The update operation preserves the cart structure:- Item Location: The item remains in its current shipment
- Shipment Options: Fulfillment and shipping options are preserved
- Addon State: Selected addons remain unless they become invalid
- Session Continuity: Cart session and authentication remain active
Related Endpoints
- Get Cart - View current cart state
- Add Line Item - Add new items to cart
- Clear Cart - Empty the entire cart
⌘I
Update Line Item
curl --request PUT \
--url https://api.firmly.work/api/v2/domains/{domain}/cart/line-items/{lineItemId} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"quantity": 123
}
'import requests
url = "https://api.firmly.work/api/v2/domains/{domain}/cart/line-items/{lineItemId}"
payload = { "quantity": 123 }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({quantity: 123})
};
fetch('https://api.firmly.work/api/v2/domains/{domain}/cart/line-items/{lineItemId}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.firmly.work/api/v2/domains/{domain}/cart/line-items/{lineItemId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'quantity' => 123
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.firmly.work/api/v2/domains/{domain}/cart/line-items/{lineItemId}"
payload := strings.NewReader("{\n \"quantity\": 123\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://api.firmly.work/api/v2/domains/{domain}/cart/line-items/{lineItemId}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"quantity\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.firmly.work/api/v2/domains/{domain}/cart/line-items/{lineItemId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"quantity\": 123\n}"
response = http.request(request)
puts response.read_body{
"cart_id": "cart_01H2XVBR8C8JS5MQSFPJ8HF9SA",
"platform_id": "shopify",
"shop_id": "staging.luma.gift",
"display_name": "Luma Store",
"cart_status": "active",
"line_items": [
{
"line_item_id": "item_01H2XVBR8C8JS5MQSFPJ8HF9SB",
"sku": "MH07-XS-Gray",
"variant_id": "MH07-XS-Gray",
"description": "Hero Hoodie - Gray XS",
"quantity": 2,
"price": {
"currency": "USD",
"value": 54.00,
"number": 5400,
"symbol": "$"
},
"line_price": {
"currency": "USD",
"value": 108.00,
"number": 10800,
"symbol": "$"
}
}
],
"shipments": [
{
"shipment_id": "ship_01H2XVBR8C8JS5MQSFPJ8HF9SC",
"line_item_ids": ["item_01H2XVBR8C8JS5MQSFPJ8HF9SB"],
"fulfillment_type": {
"id": "SHIP_TO_ADDRESS",
"name": "Ship to Address",
"description": "Standard shipping to customer address"
},
"shipping_method": {
"id": "STANDARD_GROUND",
"description": "Standard Ground Shipping",
"price": {
"currency": "USD",
"value": 49.99,
"number": 4999,
"symbol": "$"
},
"estimated_delivery": "5-7 business days"
}
}
],
"addons": {
"offers": [
{
"addon_id": "bulk_discount",
"display": {
"name": "Bulk Purchase Discount",
"description": "Save 5% on orders with 2+ items"
},
"scope": "CART",
"price": {
"currency": "USD",
"value": -130.00,
"number": -13000,
"symbol": "$"
}
}
],
"selections": []
},
"sub_total": {
"currency": "USD",
"value": 108.00,
"number": 10800,
"symbol": "$"
},
"shipping_total": {
"currency": "USD",
"value": 49.99,
"number": 4999,
"symbol": "$"
},
"tax_total": {
"currency": "USD",
"value": 10.80,
"number": 1080,
"symbol": "$"
},
"addon_total": {
"currency": "USD",
"value": 0.00,
"number": 0,
"symbol": "$"
},
"fees": [
{
"description": "Recycle fee",
"currency": "USD",
"value": 2.00,
"number": 200,
"symbol": "$"
}
],
"fee_total": {
"currency": "USD",
"value": 2.00,
"number": 200,
"symbol": "$"
},
"total": {
"currency": "USD",
"value": 170.79,
"number": 17079,
"symbol": "$"
},
"schema_version": "2.0"
}