> For the complete documentation index, see [llms.txt](https://docs.violet.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.violet.io/prism/checkout-guides/discounts/applying-discounts.md).

# Applying And Removing Discounts

There are two options for applying a discount code:

1. During initial cart creation
2. To a cart that already exists

### Apply Discount Code at Cart Creation

During cart creation by providing a list of `codes` and `merchant_ids`

Add discounts to cart creation [request](/api-reference/orders-and-checkout/carts/create-cart.md):

{% hint style="warning" %}
Merchant ids must match with the merchant id on one of the provided SKUs otherwise they will be ignored.
{% endhint %}

```json
{
  "base_currency": "USD",
  "wallet_based_checkout": false,
  "skus": [
    {
      "sku_id": 99638,
      "quantity": 1
    }
  ],
  "discounts": [
    {
      "code": "20p_off",
      "merchant_id": 22
    }
  ]
}

```

### Apply Discount Code to Existing Cart

Add discount to existing cart by providing a single `code` and `merchant_id` in the [dedicated endpoint](/api-reference/orders-and-checkout/cart-shipping/set-shipping-methods.md)

{% hint style="warning" %}
Merchant ids must match with existing sku merchant ids in cart otherwise it\
will be ignored.
{% endhint %}

```json
{
  "code": "20p_off",
  "merchant_id": 22
}

```

Both endpoints will return the entire cart with the discounts applied to correct bags. See the "discounts" sections below:

```json
{
  "id": 10632,
  "token": "b1e4032238424888b6a360b6686cc070",
  "user_id": 10002,
  "app_id": 10001,
  "developer_id": 10001,
  "bags": [
    {
      "id": 10643,
      "order_id": 10632,
      "merchant_id": 22,
      "app_id": 10001,
      "status": "IN_PROGRESS",
      "fulfillment_status": "PROCESSING",
      "financial_status": "UNPAID",
      "skus": [
        {
          "id": 10927,
          "merchant_id": 22,
          "app_id": 10001,
          "product_id": "525a1e59bebd48e7a2d431d666367b5f",
          "sku_id": 99638,
          "external_id": "MS-Champ-XL",
          "name": "Champ Tee Extra Large",
          "quantity": 1,
          "price": 2500,
          "weight": 0.5,
          "available": true,
          "status": "IN_PROGRESS",
          "product_type": "PHYSICAL",
          "line_price": 2500
        }
      ],
      "taxes": [],
      "sub_total": 2500,
      "taxes_included": false,
      "transactions": [],
      "external_checkout": true,
      "commission_rate": 0.0,
      "date_created": "2023-05-23T20:37:33+0000",
      "remorse_period_ends": "2023-06-22T20:37:33+0000",
      "currency": "USD",
      "external_currency": "USD",
      "channel": "APP",
      "platform": "MAGENTO",
      "fulfillments": [],
      "discounts": [
        {
          "id": 10367,
          "bag_id": 10643,
          "status": "APPLIED",
          "type": "CODE",
          "code": "20p_off",
          "date_created": "2023-05-23T20:37:33+0000",
          "date_last_modified": "2023-05-23T20:37:36+0000"
        }
      ],
      "wallet_based_checkout": false,
      "bag_id": 10643,
      "bag_status": "IN_PROGRESS",
      "merchant_name": "Magento Shared's Store"
    }
  ],
  "sub_total": 2500,
  "status": "IN_PROGRESS",
  "is_guest": true,
  "date_created": "2023-05-23T20:37:33+0000",
  "date_last_modified": "2023-05-23T20:37:33+0000",
  "priced": false,
  "wallet_based_checkout": false,
  "currency": "USD",
  "errors": [],
  "channel": "APP",
  "currency_symbol": "$",
  "stripe_key": "pk_test_UHg8oLvg4rrDCbvtqfwTE8qd",
  "guest": true,
  "intent_based_checkout": false,
  "order_id": 10632,
  "order_status": "IN_PROGRESS"
}

```

Once the cart is priced all available discount information is filled and returned. See "discounts" section below:

```json
{
  "id": 10632,
  "token": "b1e4032238424888b6a360b6686cc070",
  "user_id": 10002,
  "app_id": 10001,
  "developer_id": 10001,
  "customer": {
    "user_id": 10002,
    "first_name": "Evandro",
    "last_name": "Gomes",
    "email": "evandro.gomes@violet.io",
    "name": "Evandro Gomes"
  },
  "bags": [
    {
      "id": 10643,
      "order_id": 10632,
      "merchant_id": 22,
      "app_id": 10001,
      "status": "IN_PROGRESS",
      "fulfillment_status": "PROCESSING",
      "financial_status": "UNPAID",
      "skus": [
        {
          "id": 10927,
          "merchant_id": 22,
          "app_id": 10001,
          "product_id": "525a1e59bebd48e7a2d431d666367b5f",
          "sku_id": 99638,
          "external_id": "MS-Champ-XL",
          "name": "Champ Tee Extra Large",
          "quantity": 1,
          "price": 2500,
          "weight": 0.5,
          "available": true,
          "status": "IN_PROGRESS",
          "product_type": "PHYSICAL",
          "line_price": 2500
        }
      ],
      "shipping_method": {
        "type": "FLAT_RATE_PRICE",
        "carrier": "OTHER",
        "label": "Flat Rate",
        "price": 500,
        "id": 10644,
        "shipping_method_id": "flatrate_flatrate",
        "bag_id": 10643,
        "merchant_id": 22
      },
      "taxes": [],
      "sub_total": 2500,
      "shipping_total": 500,
      "tax_total": 0,
      "discount_total": 500,
      "total": 2500,
      "taxes_included": false,
      "transactions": [],
      "external_checkout": true,
      "commission_rate": 0.0,
      "date_created": "2023-05-23T20:37:33+0000",
      "remorse_period_ends": "2023-06-22T20:37:33+0000",
      "currency": "USD",
      "external_currency": "USD",
      "channel": "APP",
      "platform": "MAGENTO",
      "fulfillments": [],
      "discounts": [
        {
          "id": 10367,
          "bag_id": 10643,
          "status": "APPLIED",
          "type": "CODE",
          "value_type": "PERCENTAGE",
          "code": "20p_off",
          "amount_total": 500,
          "date_created": "2023-05-23T20:37:33+0000",
          "date_last_modified": "2023-05-23T20:38:34+0000"
        }
      ],
      "wallet_based_checkout": false,
      "bag_id": 10643,
      "bag_status": "IN_PROGRESS",
      "merchant_name": "Magento Shared's Store"
    }
  ],
  "shipping_address": {
    "name": "Evandro Gomes",
    "city": "Seattle",
    "state": "WA",
    "country": "US",
    "postal_code": "98101",
    "type": "SHIPPING",
    "first_name": "Evandro",
    "last_name": "Gomes",
    "address_1": "123 Main St NEWS"
  },
  "billing_address": {
    "name": "Evandro Gomes",
    "city": "Seattle",
    "state": "WA",
    "country": "US",
    "postal_code": "98101",
    "type": "BILLING",
    "first_name": "Evandro",
    "last_name": "Gomes",
    "address_1": "123 Main St NEWS"
  },
  "sub_total": 2500,
  "shipping_total": 500,
  "tax_total": 0,
  "discount_total": 500,
  "total": 2500,
  "status": "IN_PROGRESS",
  "is_guest": true,
  "date_created": "2023-05-23T20:37:33+0000",
  "date_last_modified": "2023-05-23T20:40:32+0000",
  "priced": true,
  "wallet_based_checkout": false,
  "currency": "USD",
  "errors": [],
  "channel": "APP",
  "currency_symbol": "$",
  "stripe_key": "pk_test_UHg8oLvg4rrDCbvtqfwTE8qd",
  "guest": true,
  "intent_based_checkout": false,
  "order_id": 10632,
  "order_status": "IN_PROGRESS"
}

```

{% hint style="warning" %}
Notice that discounts are non-blocking at Violet. It means that when a cart\
with discounts is submitted, only `APPLIED` discounts are considered, all\
other discount statuses and errors are removed from cart.
{% endhint %}

## Removing Discounts

Removing discounts is simple. Discounts can be removed from bags through the \[DELETE] `/checkout/cart/:cart_id/discounts/:discount_id` endpoint. The cart will be returned with current status without the previously applied discount.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.violet.io/prism/checkout-guides/discounts/applying-discounts.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
