Hanzo
OpenapiCommerce

Set one item's quantity in a cart; zero removes it

Sets how many of one item a cart holds, and answers the whole updated cart. This is the ONE way a cart's contents change.

POST /v1/commerce/cart/{id}/item

Addresshttps://api.hanzo.ai/v1/commerce/cart/{id}/item
MethodPOST
OperationsetCartItem
AuthAuthorization: Bearer $HANZO_API_KEY

Sets how many of one item a cart holds, and answers the whole updated cart.

This is the ONE way a cart's contents change. The quantity is the RESULT, not a delta: sending 3 leaves 3 however many were there before, so a retry is safe and a double-submit cannot double an order. ZERO REMOVES the line — there is deliberately no separate delete, because removal is the same act at the boundary value and a second spelling would be a second set of edge cases.

Name the item with EITHER product OR variant, never both. Prefer variant for anything sold in sizes, colours or tiers: the price and the stock belong to the variant, so a product-level line on a varianted product prices the wrong thing. Either may be given as an id or as the human key — a product's URL slug, a variant's SKU — which is what lets a storefront add to cart straight from a product page URL without a lookup first.

The item's price and name are CACHED onto the line as it is added, so the cart keeps the price the shopper was shown even if the catalog moves underneath it.

An item that resolves to nothing in the catalog is refused 400 and the cart is left exactly as it was; nothing is partially applied.

A named handler, not a closure, so zipdoc can lift this prose into the registry.

Request

5 fields, body application/json (required).

FieldInTypeRequiredDescription
idpathstringyesID is the cart to amend, from the path.
idbodystringID is the cart to amend, from the path.
productbodystringProduct names the catalog product to set, by its id or its URL slug.
quantitybodyintegerQuantity is how many of that item the cart should hold AFTER this call — it is the resulting count, not a delta, so sending 3 twice leaves 3 and not 6.
variantbodystringVariant names the specific sellable variant to set, by its id or its SKU.

Response

StatusBodyMeaning
200Cartok

200 body — 23 fields.

FieldInTypeAlwaysDescription
createdAtbodystringCreatedAt is when the cart was opened, RFC3339.
currencybodystringCurrency is the ISO 4217 code every amount below is denominated in.
discountCentsbodyintegerDiscountCents is what coupons and promotions took off, in whole cents.
emailbodystringEmail is the shopper's address, when the cart carries one.
idbodystringID is the cart's id — what every other cart op addresses it by, and what a storefront persists against the browser session.
itemsbodyCartItem[]Items are the cart's lines, in the order they were added.
items[].freebodybooleanFree reports a line that costs nothing because a coupon or a promotion made it so, rather than because its price is zero.
items[].idbodystringID is the line's identity — the variant id when the line is a variant, otherwise the product id.
items[].kindbodystringKind is "variant" when this line is a specific sellable variant and "product" when it is the product itself.
items[].namebodystringName is the item's display name, cached onto the line when it was added so a cart renders without a second read.
items[].priceCentsbodyintegerPriceCents is the unit price in whole cents, cached at the moment the line was added.
items[].quantitybodyintegerQuantity is how many units of this item the cart holds.
items[].skubodystringSKU is the line's stock-keeping unit — the variant's when it has one, otherwise the product's.
lineTotalCentsbodyintegerLineTotalCents is the sum of the lines before any discount, in whole cents.
orderbodystringOrder is the order this cart became, once checkout completed it.
shippingCentsbodyintegerShippingCents is the shipping charge, in whole cents.
statusbodystringStatus is "active" for a cart still being filled, "ordered" once checkout turned it into an order, and "discarded" when the shopper abandoned it.
storebodystringStore is the storefront the cart is being filled on.
subtotalCentsbodyintegerSubtotalCents is LineTotalCents less DiscountCents, in whole cents.
taxCentsbodyintegerTaxCents is the sales tax, in whole cents.
totalCentsbodyintegerTotalCents is what the shopper pays: subtotal plus shipping plus tax, in whole cents.
updatedAtbodystringUpdatedAt is when the cart was last amended, RFC3339.
userbodystringUser is the signed-in shopper this cart belongs to, empty for a guest cart.

Failure carries the platform error shape — see Errors.

Examples

hanzo has no subcommand for this operation — the CLI serves only what cloud's live route table confirms. Use HTTP or an SDK.


Commerce API · All Hanzo APIs · Interactive reference

How is this guide?

On this page