Update Item Quantity
updateItemQuantity
allows you to update the quantity of an item on an order. The quantity must be greater than 0. Use removeItem
if you want to remove an item from an order.
Usage
updateItemQuantity
takes in the following object.
interface UpdateItemQuantityRequest {
orderItemId: string;
quantity: number;
orderId?: string;
}
orderItemId
is theID
of a line item on the order. The order is found on the cart resource, withline_items
on the order being an array of line items. For example, to pick the first line item’s ID on the order you’d useitem.order.line_items.0.id
.quantity
is the new quantity number you want for your order’s item (e.g.5
).orderId
is the ID of the order you’re updating. Only needed if you’re managing multiple orders. Otherwise exclude the field, and the SDK will use the existing order from your cookies.
Example
const updateItemQuantityRequest = {
orderItemId: '11ee2722e42886d182fa089e019fd17a',
quantity: 2
};
try {
const response = await sdk.cart.updateItemQuantity(updateItemQuantityRequest);
} catch (error) {
// Handle errors
}
Return Value and Error Handling
updateItemQuantity
has the same return value and error handling that is documented for addItem
.