How to work with the APIs for product pricing and discounts.
This page describes rules that apply across the pricing and discounts APIs. For what Prices and Discounts are and how they behave, see the Pricing and discounts overview.
APIs in this topic
| Resource | Purpose | Reference |
|---|---|---|
| Standalone Prices | Store your product prices as standalone resources, especially with a large number of prices. | Standalone Prices |
| Product Discounts | Reduce certain Product Prices. | Product Discounts |
| Cart Discounts | Change the Prices of different elements within a Cart. | Cart Discounts |
| Discount Codes | Give specific Cart Discounts to eligible Customers. | Discount Codes |
| Discount Groups | Group Cart Discounts and apply the best discount from the group to a Cart. | Discount Groups |
Data model
- For Embedded Prices, the discounted value is stored in the Price
discountedfield. - For Standalone Prices, the discounted value is stored in the StandalonePrice and StagedStandalonePrice
discountedfields.
Working with the APIs
Price modes
The Product
priceMode determines the type of Price used for a Product Variant. If the priceMode is not set, as a default, Product Variants use Embedded Prices.- For existing Products using Embedded Prices, use the Set PriceMode update action to change the price mode.
- For new Products, create a Product with
priceModeasStandalone.
Embedded Prices
Embedded Prices are stored within a ProductVariant, and are associated to it through its
prices field.Embedded Prices are managed and queried using the Products API. You can add Prices when creating a Product, or manage Prices of an existing Product using the Add Price, Set Prices, Change Price, or Remove Price update actions.
Standalone Prices
Standalone Prices are managed and queried using the Standalone Prices API, independent from your Products, thus contributing to better query performance.
External Prices
Since external prices are not part of the product catalog, they are not available on the Product Search API as well as the Product Projection Search API for filtering, faceting, or sorting products by price.
You can set an external price for the Line Item when creating or updating a Cart using the following actions: Add LineItem, Remove LineItem, Change LineItem Quantity, Set LineItem Price, or Set LineItem TotalPrice.
If the LineItem's
priceMode is ExternalPrice, set the externalPrice value. The totalPrice of the LineItem is automatically calculated by multiplying the externalPrice by the quantity.If the LineItem's
priceMode is ExternalTotal, set the externalTotalPrice value (unit price multiplied by the quantity). The totalPrice of the LineItem is set from the value defined in externalTotalPrice.Your code should be able to find the correct prices to display on your storefront and set the Line Item price when it's added to a Cart.
Tiered pricing
When the PriceTier
minimumQuantity is reached, the Price tier is applied for the entire quantity of a Product Variant added as Line Item to a Cart.Price selection in API responses
Both types of price selection add the additional
price field to the ProductVariant and LineItem respectively in API responses. The price field is not populated for ShoppingListLineItem because price selection is not supported in the Shopping List context.The returned ProductVariant
price field—added in API responses—contains the Price that matches most of the Price-selection parameters.The price is shown only when the timestamp of the request is within
validFrom and validUntil range of Embedded Price or StandalonePrice.-
Line Item price selection: When you create a Cart or add a LineItem to a Cart, the
priceis determined by the Carts API based on the following parameters:-
Cart
customerGroup: maps tocustomerGroupof Price or StandalonePrice -
Cart
country: maps tocountryof Price or StandalonePrice -
Customer
customerGroupAssignments: maps tocustomerGroupof Price or StandalonePrice. For more information, see Fallback logic for multiple Customer Groups. -
Business Unit
customerGroupAssignments: maps tocustomerGroupof Price or StandalonePrice. For more information, see Fallback logic for multiple Customer Groups.BothbusinessUnit.customerGroupAssignmentsandcart.businessUnitfields must be defined (non-null) for B2B-specific prices to apply on the cart; otherwise, the platform selects B2C-specific prices.- If the Business Unit
customerGroupAssignmentsfield is an empty list ([]), the base price applies as no Customer Group-specific prices are available. - If the Business Unit
customerGroupAssignmentsfield is not set, the CartcustomerGroupand CustomercustomerGroupAssignmentsfields are used (as a fallback) to determine eligible Customer Groups, provided the Cart has acustomerId. If nocustomerIdis set, the base price applies.
- If the Business Unit
Scoped Price search
Scoped Price search—that includes filter, facet, and sort options—only works with Embedded Prices. Using these options on Products with
Standalone ProductPriceMode yields inconsistent results, as only Embedded Prices are taken into account.In case of a full match—where a Price matching all Price-selection parameters provided with the search request exists—the ProductVariants returned with the search result contains the
scopedPrice field. In case of a partial match, this field is not present.Scoped Price search does not have a fallback behavior, and does not take the Price validity dates into consideration. To ensure only Products with valid Prices are returned, remove Prices that are no longer valid. For Prices to become valid at a later time, do not publish them before their
validFrom date, and search for the current Product Projection.For worked examples of Scoped Price search, see Product Projection Search.
Product Discounts
If multiple active Product Discounts match a Price, then the ProductDiscount
sortOrder determines which one applies.Product Discounts are managed and queried using the Product Discounts API.
Cart Discounts
Cart Discounts can be used to discount different elements of a Cart, some of which include:
- A discount on any item in a cart with CartDiscountLineItemsTarget or CartDiscountCustomLineItemsTarget
- A discount on the shipping cost of a cart with CartDiscountShippingCostTarget
- A discount on a cart's total with CartDiscountTotalPriceTarget
- A 'Buy X, get Y free' discount with CartDiscountValueGiftLineItemDraft
- A 'Buy X items, get Y of them at a discounted rate' discount with MultiBuyLineItemsTarget or MultiBuyCustomLineItemsTarget. Note that you can only apply a percentage-off discount on eligible items.
You can also use CartDiscountPatternTarget. It is a more powerful option and lets you apply an amount, a fixed price, or percentage discount to eligible items.
Gift Line Items are ignored by MultiBuyLineItemsTarget and CartDiscountPatternTarget discounts.
Cart Discounts can be defined globally for a Project, or be specific to one or more Stores in a Project. In the latter case, the Discount is only applied to Carts that belong to one of the Stores referenced in the CartDiscount
stores array. If the array is empty or unspecified, the Discount applies (globally) to all Carts.You can avoid applying further Cart Discounts to the Cart by setting the
stackingMode to StopAfterThisDiscount on the CartDiscount that must be applied last.The stacking mode does not control free shipping as defined via
freeAbove on a ShippingRate. To avoid unwanted scenarios, we highly recommend not using Cart Discounts on shipping target and freeAbove together.Cart Discounts are managed and queried using the Cart Discounts API.
Cart Discounts are recalculated every time a Discount Code, LineItem, or CustomLineItem is added or removed from a Cart, or when an Order is created from a Cart.
Discount Codes
Discount Codes are managed and queried using the Discount Codes API.
Discount Groups
You can only group Cart Discounts if they are not specific to a Store and they target Line Items (that is, CartDiscounts with
target as lineItems, customLineItems, multiBuyLineItems, multiBuyCustomLineItems, or pattern).To remove a Cart Discount from a Discount Group, use the Set DiscountGroup action and set the sort order for the Cart Discount again.
Discounts Groups are managed and queried using the Discount Groups API.
Direct Discounts
Direct Discounts are always active and valid, use the default StackingMode
Stacking, and do not have a sorting order. They apply in the order listed in the directDiscounts array of the Cart or Order.For all three discount types to coexist,
directDiscountsIgnoreCartDiscounts must be false on the Cart.To avoid losing a negotiated reduction,
participateInBestDealSelection must be set to false on the DirectDiscountDraft.To update or add Direct Discounts to an Order, use the Set DirectDiscounts update action.
Discount combination mode
In the
BestDeal DiscountCombinationMode, Product Discounts and Cart Discounts can both be present on the same Cart, but only one discount type applies per Line Item.Eventual consistency
When you create, update, or delete a Product Discount, the Prices are updated in an eventually consistent manner. Both Embedded Prices and StandalonePrices associated to a ProductVariant are updated, regardless of the Product's priceMode value.
The time to update can vary—between a fraction of a second to several hours—depending on the following factors:
- The number of Products and their size
- The number of Products affected by Discount predicates
- The number of Prices to be updated
Limits
With Embedded Prices, you can store up to
100 Prices for each Product Variant. For more flexibility with pricing your products with higher limits, see Standalone Prices.When using Embedded Prices, keep the JSON document size in mind. A Product and all its Prices are stored in a single JSON document. As Price count and Product Type complexity grow, you may approach the document size limit.
A maximum number of
50 000 Standalone Prices can be specified per ProductVariant. This is a soft limit that can be increased per Project after a performance impact review. See Limit increase guidance.Product Discounts are subject to a limit in a Project.
Cart Discounts are subject to a limit in a Project.
Discount Groups are subject to a limit in a Project.
Discount Codes are subject to a limit in a Project.