How to work with the APIs for inventory management.
APIs in this topic
| Resource | Purpose | Reference |
|---|---|---|
| Inventory | Track stock quantity per SKU and optionally per supply channel. | Inventory |
| Reservations | Temporarily reserve available quantity for customers when they add a Line Item to a Cart. | Reservations |
Data model
supplyChannel field.Working with the APIs
Quantity limits
minCartQuantity: the minimum allowed quantity for a Line Item in the Cart. This prevents customers from adding quantities below the specified threshold.maxCartQuantity: the maximum allowed quantity for a Line Item in the Cart. This caps the quantity a customer can purchase at once.
Workarounds
maxCartQuantity for a single Product Variant, consider the following options:- Custom field workaround: add custom fields with different values to Line Items. This allows creating multiple Line Items for the same Product Variant, each subject to the quantity limits individually. The total quantity across all Line Items can exceed the limit of a single Line Item.
- Adjust or remove quantity limits: modify the
minCartQuantityormaxCartQuantityvalues on the InventoryEntry, or remove the limits entirely. - Use another InventoryEntry: create or use a different InventoryEntry for the same SKU without quantity limits, potentially with a different supply channel.
Reservations
- The Cart's inventory mode is
ReserveOnCart. - One or more Line Item's inventory mode is set to
ReserveOnCartbut the Cart has a different inventory mode.
Set the default expiration
ReserveOnCart InventoryMode on Carts or individual Line Items. This step ensures that stock is not held indefinitely. You only have to set this once per Project.Reserve items
reservationExpirationInMinutes value set in the corresponding InventoryEntry, or if absent, the Project-level reservation expiration time. Reserved Line Items include a reservation field containing the reservation reference, which you can then expand to view additional details. There is no dedicated API endpoint to query or manage Reservation resources directly; they are only accessible through reference expansion on a Cart's Line Items.Reserve all items in a Cart
ReserveOnCart during Cart creation.The following applies:
- If all items could be reserved, the Cart creation succeeds, and no warnings are present in the response.
- If some items could not be reserved, the Cart creation succeeds, however, those items are not added to the Cart. The response will contain a CannotCreateReservation warning for each Line Item that could not be reserved/added.
- If no Line Items could be reserved, the Cart creation fails.
Reserve individual Line Items
ReserveOnCart. You can do this when adding items to a Cart, or for existing items, using the Set LineItem InventoryMode update action.The following applies:
- When changing an existing Line Item's inventory mode to
ReserveOnCartand there is insufficient stock available, the response contains a CannotCreateReservation warning. The Line Item remains in the Cart and the inventory mode remains unchanged. - When adding a new Line Item with the inventory mode set to
ReserveOnCart, and there is insufficient stock available, the response contains a CannotCreateReservation warning, and the Line Item is not added to the Cart.
Update a reservation
The following scenarios illustrate how to update an existing reservation:
Change the reserved quantity
availableQuantity of the associated InventoryEntry and extends the reservation expiration time.Extend the reservation expiration
To prevent Order creation failures due to a last-second expiration, the platform automatically attempts to renew expired Cart reservations during the Order creation process.
Release a reservation
ReserveOnCart to another inventory mode using the Set LineItem InventoryMode update action. This action increases the availableQuantity of the associated InventoryEntries accordingly.Handle reservation warnings
The following warnings may appear in Cart responses when working with reservations:
| Warning | Appearance |
|---|---|
| CannotCreateReservationWarning | Appears when creating a Cart with ReserveOnCart but one or more Line Items lack sufficient stock. No reservation is created. See Reserve items. |
| CannotUpdateReservationWarning | Appears when updating a Line Item's quantity but the reservation cannot be updated (usually due to insufficient stock). The Line Item quantity remains unchanged. |
| CannotChangeReservationExpiryWarning | Appears when trying to extend an expired reservation but insufficient stock prevents reacquiring it. The action succeeds, but the reservation expiry cannot be extended. |
Further reading
To learn more about implementing reservations, see the following tutorials:
- Reserve stock on Cart: learn how to automatically reserve items in a Cart.
- Reserve stock on demand and freeze prices: learn how to reserve items on demand while freezing all prices.
Eventual consistency
Inventory checks and consistency
- Direct updates to InventoryEntry using the Inventory API are strongly consistent and immediately visible.
- Order operations using the
ReserveOnOrderorTrackOnlyinventory modes are eventually consistent. This means that changes to theavailableQuantityandquantityOnStockfields of the corresponding InventoryEntry may take up to 10 seconds to appear. - Reservation-based updates to resources using the
ReserveOnCartinventory mode are eventually consistent. This means that changes to theavailableQuantityandquantityOnStockfields of the corresponding InventoryEntry may take up to 10 seconds to appear. The following endpoint and update actions are affected if the Cart or Line Items use theReserveOnCartinventory mode:- Create Order from Cart
- Cart update actions
changeLineItemQuantity,addLineItem,removeLineItem, andsetLineItemInventoryMode.
availableQuantity and quantityOnStock fields on the InventoryEntry are eventually aligned with this internal collection, but the delay does not affect reservation guarantees or cause failed Order placements due to stockouts.To obtain the most accurate stock data (for example, when adding items to a cart, performing fulfillment checks, etc.), query the corresponding InventoryEntry. We recommend that you only fetch the data that you need. For example, avoid loading all InventoryEntries for a SKU when you only need supply channel availability or specific stock details.
availability field in ProductVariant. This provides an overview of stock levels which may lag behind real-time stock levels by a few seconds. However, checking inventory in this manner reduces the need to query the Inventory API directly.Messages and events
reorderPoint and safetyStock thresholds on the stockLevels field of each InventoryEntry. For the Messages sent, see InventoryEntryReorderPoint and InventoryEntrySafetyStock.