# Apply promo code

Applies a code to a cart. When a promo code is applied, the cart total is recalculated to reflect a discount on the entire cart or on selected items. Bonus items may also be added to the cart. The discount is applied at checkout, while bonus items are granted after successful payment. Before payment, the user can remove the promo code, which cancels the discount and removes the bonus items from the cart.

Endpoint: POST /v2/project/{project_id}/promocode/redeem
Version: 2.0.0
Security: AuthForCart

## Path parameters:

  - `project_id` (integer, required)
    Project ID. You can find this parameter in your Publisher Account next to the project name and in the browser address bar when working with a project. The URL has the following format: https://publisher.xsolla.com//projects/.
    Example: 44056

## Request fields (application/json):

  - `coupon_code` (string)
    Unique code of promo code. Contains letters and numbers.
    Example: "SUMMER2021"

  - `cart` (object,null)

  - `cart.id` (string, required)
    Cart ID.

  - `selected_unit_items` (object)
    Platform-specific game key selected as a bonus by the user. Pass the [received](/api/liveops/promotions-coupons/get-coupon-rewards-by-code#promotions-coupons/get-coupon-rewards-by-code/t=response&c=200&path=bonus/item) bonus.item.sku as a key, and the chosen bonus.item.unit_items.sku as its value.

## Response 200 fields (application/json):

  - `cart_id` (string)
    Cart ID.
    Example: "cart_id"

  - `price` (object,null)
    Cart price.
    Example: {"amount":"6150.0000000000000000","amount_without_discount":"6150.0000000000000000","currency":"USD"}

  - `price.amount` (string)
    Example: "6150.0000000000000000"

  - `price.amount_without_discount` (string)
    Example: "6150.0000000000000000"

  - `price.currency` (string)
    Example: "USD"

  - `is_free` (boolean)
    Whether the item is free.

  - `items` (array)
    Example: [{"attributes":[],"description":"Take it, take it all! All of Xsolla's riches in one Mega Booster.","groups":[{"external_id":"powerups","name":"Power Ups"}],"image_url":"https://cdn.xsolla.net/img/misc/images/e9f2f4a634bc96ea03b5d5ceadd7c55f.png","is_free":false,"name":"Xsolla Booster Mega","price":{"amount":"50.0000000000000000","amount_without_discount":"100.0000000000000000","currency":"USD"},"quantity":123,"sku":"com.xsolla.booster_mega_1","type":"virtual_good","virtual_item_type":"consumable","virtual_prices":[],"promotions":[{"name":"Bonus promotion","date_start":"2020-04-15T16:16:00+03:00","date_end":"2026-04-15T16:16:00+03:00","discount":{"percent":"50.00"},"bonus":[{"quantity":1,"name":"Xsolla Minigun","image_url":"https://cdn.xsolla.net/img/misc/images/2fc5c491a47413a8e8000447889093c2.png","sku":"com.xsolla.minigun_1","type":"virtual_good"}]}],"can_be_bought":true,"vp_rewards":[{"item_id":175232,"sku":"com.xsolla.value_point_1","amount":130,"name":"Value point","image_url":"https://cdn3.xsolla.com/img/misc/images/54c0cf9d345817cdacfdde198db178e0.jpg","is_clan":false},{"item_id":186321,"sku":"com.xsolla.clan_value_point_1","amount":50,"name":"Clan Reward VP 1","image_url":"https://cdn3.xsolla.com/img/misc/images/54c0cf9d345817cdacfdde198db178e0.jpg","is_clan":true}],"limits":{"per_user":{"available":3,"recurrent_schedule":{"interval_type":"weekly","reset_next_date":1746057600},"total":5}},"periods":[{"date_from":"2020-08-11T10:00:00+03:00","date_until":"2020-08-11T20:00:00+03:00"}]}]

  - `items.sku` (string)

  - `items.groups` (array)

  - `items.groups.external_id` (string)

  - `items.groups.name` (string)

  - `items.name` (string,null)

  - `items.type` (string)

  - `items.description` (string)

  - `items.image_url` (string)

  - `items.quantity` (integer)

  - `items.is_free` (boolean)
    Whether the item is free.

  - `items.promotions` (array)
    Applied promotions for specific items in the cart. The array is returned in the following cases:

* A discount promotion is configured for a specific item.

* A promo code with the Discount on selected items setting is applied.

If no item-level promotions are applied, an empty array is returned.

  - `items.promotions.name` (string)

  - `items.promotions.date_start` (string,null)

  - `items.promotions.date_end` (string,null)

  - `items.promotions.discount` (object,null)

  - `items.promotions.discount.percent` (string,null)

  - `items.promotions.discount.value` (string,null)

  - `items.promotions.bonus` (array)

  - `items.promotions.bonus.sku` (string)

  - `items.promotions.bonus.quantity` (integer)

  - `items.promotions.bonus.type` (string)
    Bonus item type.
    Enum: "virtual_good", "virtual_currency", "bundle", "physical_good", "game_key", "nft"

  - `items.promotions.bonus.name` (string)
    Bonus item name. Not available for physical_good bonus item type.

  - `items.promotions.bonus.image_url` (string)
    Bonus item image URL. Not available for physical_good bonus item type.

  - `items.promotions.bonus.bundle_type` (string)
    Bonus bundle item type. Available only for bundle bonus item type.
    Enum: "standard", "virtual_currency_package"

  - `items.promotions.limits` (object)

  - `items.promotions.limits.per_user` (object)

  - `items.promotions.limits.per_user.available` (integer)

  - `items.promotions.limits.per_user.total` (integer)

  - `items.can_be_bought` (boolean)
    If true, the user can buy an item.

  - `items.vp_rewards` (array)
    List of value point rewards for the item.

  - `items.vp_rewards.item_id` (integer)
    Internal unique item ID.

  - `items.vp_rewards.sku` (string)
    Unique value point ID.

  - `items.vp_rewards.amount` (integer)
    Amount of value points.

  - `items.vp_rewards.name` (string)
    Value point name.

  - `items.vp_rewards.image_url` (string)
    Image URL.

  - `items.vp_rewards.is_clan` (boolean)
    Whether the value point is used in clan reward chains.

  - `items.loyalty_rewards` (array)
    Loyalty points the user receives as a reward for purchasing the item.

  - `items.loyalty_rewards.name` (string)
    Loyalty point name.

  - `items.loyalty_rewards.sku` (string)
    Loyalty point SKU. Pass this value in the loyalty_point_sku parameter of other API calls, for example, when creating an order paid with loyalty points.

  - `items.loyalty_rewards.description` (string)
    Loyalty point description.

  - `items.loyalty_rewards.image_url` (string,null)
    Image URL.

  - `items.loyalty_rewards.amount` (integer)
    Number of loyalty points the user receives for purchasing the item.

  - `items.limits` (object,null)
    Item limits.

  - `items.limits.per_user` (object,null)
    Item limits for a user.

  - `items.limits.per_user.total` (integer)
    Maximum number of items a single user can purchase.
    Example: 5

  - `items.limits.per_user.available` (integer)
    Remaining number of items the current user can purchase.
    Example: 3

  - `items.limits.per_user.recurrent_schedule` (any)

  - `items.limits.per_user.limit_exceeded_visibility` (string)
    Determines the visibility of the item in the catalog after the purchase limit is reached, until the next limit reset.

Applies to items for which recurring limit resets are configured in the recurrent_schedule array.

If limit resets are not configured, the item doesn't appear in the catalog after the purchase limit is reached,
regardless of the limit_exceeded_visibility value.

Possible values:
- show — The item is returned in catalog retrieval API calls after the purchase limit is reached. In client-side
catalog retrieval API calls, once the limit is reached, the item is returned with the can_be_bought: false flag. The
next reset date is returned in reset_next_date.
- hide — The item is not returned in catalog retrieval API calls after the purchase limit is reached, until the
limit is reset.
    Enum: "show", "hide"

  - `items.limits.per_item` (object,null)
    Item limits for an item.

  - `items.limits.per_item.total` (integer)
    Maximum number of items all users can purchase.
    Example: 5

  - `items.limits.per_item.available` (integer)
    Remaining number of items all users can purchase.
    Example: 3

  - `items.periods` (array,null)
    Item sales period.

  - `items.periods.date_from` (string)
    Date when the specified item will be available for sale.
    Example: "2020-08-11T10:00:00+03:00"

  - `items.periods.date_until` (string,null)
    Date when the specified item will become unavailable for sale. Can be null.
    Example: "2020-08-11T20:00:00+03:00"

  - `rewards` (object)

  - `rewards.bonus` (array)

  - `rewards.bonus.item` (object)

  - `rewards.bonus.item.sku` (string)
    Unique item ID. The SKU may contain only lowercase and uppercase Latin alphanumeric characters, periods, dashes, and underscores.
    Example: "game_01"

  - `rewards.bonus.item.name` (string)
    Item name.
    Example: "Game name"

  - `rewards.bonus.item.type` (string)
    Type of item. Possible values:virtual_good — virtual itemsvirtual_currency — virtual currencybundle — bundleunit — game key package
    Example: "unit"

  - `rewards.bonus.item.description` (string)
    Item description.
    Example: "Game description"

  - `rewards.bonus.item.image_url` (string)
    Image URL.
    Example: "https://cdn.xsolla.net/img/misc/images/b79342cdf24f0f8557b63c87e8326e62.png"

  - `rewards.bonus.item.unit_items` (array)
    Array of platform-specific game keys. Used only when the item type is unit (bonus.item.type = 'unit'). If the game key package includes platform-specific keys, the user can choose one of them as a bonus.

  - `rewards.bonus.item.unit_items.sku` (string)
    Unique platform-specific game key package ID. Allowed characters: a–z, A–Z, 0–9, period (.), hyphen (-), underscore (_). It combines bonus.item.​sku and bonus.item.unit_items.drm_sku values. E.g., if bonus.item.​sku = 'cool_game' and bonus.item.unit_items.drm_sku = 'steam', the value will be cool_game_steam.
    Example: "cool_game_steam"

  - `rewards.bonus.item.unit_items.is_free` (boolean)

  - `rewards.bonus.item.unit_items.type` (string)
    Indicates that the item is a game key.
    Enum: "game_key"

  - `rewards.bonus.item.unit_items.name` (string)
    Game title.
    Example: "Awesome Game"

  - `rewards.bonus.item.unit_items.drm_name` (string)
    DRM name.
    Example: "Steam"

  - `rewards.bonus.item.unit_items.drm_sku` (string)
    Unique DRM ID used as a suffix to indicate a platform-specific game key. Allowed characters: a–z, A–Z, 0–9, period (.), hyphen (-), underscore (_).
    Example: "steam"

  - `rewards.bonus.quantity` (number)
    Item quantity.

  - `rewards.discount` (object,null)
    Percent discount.
The price of cart will be decreased using a value calculated by using this percent and then rounded to 2 decimal places.

  - `rewards.discount.percent` (string)
    Example: "10.00"

  - `rewards.discounted_items` (array,null)
    List of items that are discounted by a promo code.

  - `rewards.discounted_items.sku` (string, required)
    Item SKU.

  - `rewards.discounted_items.discount` (object, required)

  - `rewards.discounted_items.discount.percent` (string, required)
    Percent discount.

The price of cart item will be decreased using a value
calculated by using this percent and then rounded
to 2 decimal places.

  - `rewards.is_selectable` (boolean)
    If true, the user should choose the bonus before redeeming a promo code.

## Response 401 fields (application/json):

  - `statusCode` (integer)
    Example: 401

  - `errorCode` (integer)
    Example: 1501

  - `errorMessage` (string)
    Example: "[0401-1501]: Authorization failed: Provide authorization"

## Response 403 fields (application/json):

  - `statusCode` (integer)
    Example: 403

  - `errorCode` (integer)

  - `errorMessage` (string)
    Example: "Authorization header not sent."

  - `transactionId` (string)
    Example: "x-x-x-x-transactionId-mock-x-x-x"

## Response 404 fields (application/json):

  - `statusCode` (integer)
    Example: 404

  - `errorCode` (integer)
    Example: 4001

  - `errorMessage` (string)
    Example: "[0401-9807]: Enter valid promo code."

## Response 422 fields (application/json):

  - `statusCode` (integer)
    Example: 422

  - `errorCode` (integer)
    Example: 1102

  - `errorMessage` (string)
    Example: "[0401-1102]: Unprocessable Entity. The property `coupon_code` is required"

  - `transactionId` (string)
    Example: "x-x-x-x-transactionId-mock-x-x-x"


