Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Promotion API handlers

Manage promotions (promo codes) applied to shopping carts.

POST Promotion (Add)

HTTP Verb – POST

URL – /api/v1/carts/{cartId}/promotions

Description – Apply a promotion code to a cart

Base – HandlerBase<AddPromotionParameter, AddPromotionResult>

Handlers

OrderHandlerDescription
500GetCartRetrieves the cart using the CartId parameter via the CartService. Returns error if the cart is not found.
600ValidatePromotionCodeChecks if the promotion code is already applied to the cart. Validates the promotion code against the promotion engine. Returns appropriate error messages for already-applied, expired, or invalid codes.
700ApplyPromotionCreates an OrderPromotionCode entity and adds it to the cart. If AllowMultiplePromotions setting is false, removes existing promotion codes first. Calls the promotion engine to apply promotions and saves changes.
800ValidateAppliedPromotionVerifies the promotion was successfully applied by checking CustomerOrderPromotions. If the promotion was not applied, removes the promotion code and returns an error with the specific reason (for example, customer limit exceeded or order total requirement not met).
900CreatePromotionDtoCreates a PromotionDto from the applied CustomerOrderPromotion. Formats the display message with translation support and adds a result message indicating the promotion was applied. Adds a warning if the promotion is not yet live.

GET Promotion Collection

HTTP Verb – GET

URL – /api/v1/carts/{cartId}/promotions

Description – Get all promotions applied to a cart

Base – HandlerBase<GetPromotionCollectionParameter, GetPromotionCollectionResult>

Handlers

OrderHandlerDescription
500GetCartRetrieves the cart using the CartId parameter via the CartService. Returns error if the cart is not found.
600CreatePromotionDtosCreates a list of PromotionDto objects from the cart's CustomerOrderPromotions collection, using the currency format provider, promotion amount provider, and entity translation service.

GET Promotion

HTTP Verb – GET

URL – /api/v1/carts/{cartId}/promotions/{promotionId}

Description – Get a single promotion applied to a cart

Base – HandlerBase<GetPromotionParameter, GetPromotionResult>

Handlers

OrderHandlerDescription
500GetCartRetrieves the cart using the CartId parameter via the CartService. Returns error if the cart is not found.
600CreatePromotionDtoFinds the CustomerOrderPromotion matching the specified PromotionId. Returns NotFound error if not found. Creates a PromotionDto from the matched promotion.

DELETE Promotion Collection (Remove All)

HTTP Verb – DELETE

URL – /api/v1/carts/{cartId}/promotions

Description – Remove all promotions from a cart

Base – HandlerBase<RemovePromotionCollectionParameter, RemovePromotionCollectionResult>

Handlers

OrderHandlerDescription
500GetCartRetrieves the cart for modification using the CartId parameter. Returns early (without error) if the cart is empty or voided. Returns error if the cart is not found.
600RemovePromotionsDeletes all OrderPromotionCode entities from the cart. Clears promotions via the promotion engine. Flags the cart for recalculation of promotions, shipping, and tax. Saves changes.

DELETE Promotion (Remove Single)

HTTP Verb – DELETE

URL – /api/v1/carts/{cartId}/promotions/{promotionId}

Description – Remove a specific promotion from a cart

Base – HandlerBase<RemovePromotionParameter, RemovePromotionResult>

Handlers

OrderHandlerDescription
500GetCartRetrieves the cart for modification using the CartId parameter. Returns early (without error) if the cart is empty or voided. Returns error if the cart is not found.
600GetPromotionQueries CustomerOrderPromotion entities matching the CartId and PromotionId parameter. Returns NotFound error if no matching promotions exist.
700RemovePromotionFor each matched CustomerOrderPromotion, removes the associated OrderPromotionCode (respecting case sensitivity settings), clears promotion results via the promotion result service, removes the CustomerOrderPromotion entity, and saves.
800RecalculatePromotionsFlags the cart for recalculation of promotions, shipping, and tax. Calls the promotion engine to reapply remaining promotions and saves changes.