Change the quantity of a cart line
const url = 'https://apibase.ecomweb.app/api/v1/stores/example/cart/items/example';const options = { method: 'PUT', headers: { 'x-storefront-api-key': '<x-storefront-api-key>', Authorization: 'Bearer <token>', 'Content-Type': 'application/json' }, body: '{"quantity":3}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request PUT \ --url https://apibase.ecomweb.app/api/v1/stores/example/cart/items/example \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --header 'x-storefront-api-key: <x-storefront-api-key>' \ --data '{ "quantity": 3 }'Sets the quantity of the line identified by itemId. A quantity of 0 or less removes the line and the response then carries item: null. The body is not validated up front: a missing or invalid quantity is not rejected with a 400. The request fails with a server error when the shopper has no cart yet.
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”The cart line ID, as returned in the cart’s items[].id or when the line was added.
The store’s ref, as returned by GET /stores.
Request Bodyrequired
Section titled “Request Bodyrequired”object
The new quantity. A quantity of 0 or less removes the line.
Example
3Responses
Section titled “Responses”object
The line after the change, or null when the quantity was 0 or less and the line was removed.
object
Cart line ID.
ID of the cart the line belongs to.
ID of the product.
ID of the variant, or null when the line has none.
Units in the line.
When the line was added, as an ISO 8601 timestamp.
When the line last changed, as an ISO 8601 timestamp.
ID of the cart.
Example generated
{ "item": { "id": "example", "cart_id": "example", "product_id": 1, "variant_id": 1, "quantity": 1, "created_at": "example", "updated_at": "example" }, "cart_id": "example"}The key is missing, invalid, revoked or expired.
object
The HTTP status code.
What went wrong; validation failures list one message per problem.
The HTTP status text, such as Bad Request.
object
A stable, machine-readable error code.
A human-readable explanation.
Extra context about the error, when there is any.
object
When the error happened, as an ISO 8601 timestamp.
Example generated
{ "statusCode": 1, "message": [ "example" ], "error": "example"}The key may not do this: a missing scope, a readonly key, a publishable key on a Store API route, or a disallowed origin.
object
The HTTP status code.
What went wrong; validation failures list one message per problem.
The HTTP status text, such as Bad Request.
object
A stable, machine-readable error code.
A human-readable explanation.
Extra context about the error, when there is any.
object
When the error happened, as an ISO 8601 timestamp.
Example generated
{ "statusCode": 1, "message": [ "example" ], "error": "example"}