# 30% off with a coupon code

> For the complete documentation index, see [llms.txt](https://docs.talon.one/llms.txt).

Let's create a [promotion rule](/docs/product/rules/overview.md#promotion-rules) that provides a **30% discount** to customers who enter the `SUMMER2023` coupon code.
The code has unlimited redemptions and no further limitations.

This tutorial uses concepts covered in the [Create a discount based on session value tutorial](/docs/product/tutorials/sample-campaigns/discount-based-on-session-value.md),
where we learned how to set up a rule triggering on certain [events](/docs/dev/concepts/entities/events.md).

## Create the coupon promotion

In the current scenario, let's use one rule and name it `30% off with coupon code`.

### Condition

Talon.One offers many [conditions](/docs/product/rules/conditions/available-conditions.md).
In our case we need the following condition:

1. Click **Add condition** and select **Coupon code is valid**.

This condition allows you to check whether the coupon codes provided in the session by
the customer are valid. This condition also automatically redeems the coupon code when the customer
session is closing. Learn more about [Customer session states](/docs/dev/concepts/entities/customer-sessions.md#customer-session-states).

### Effect

Let's set the **Discount session total** effect:

1. Set the **Name** to something descriptive, such as `30% off`.
1. Set the **Discount value** to <Attribute name="[Session.Total]"/>`*30%`.

As in the previous tutorials, we calculate the discount value using the same <Attribute name="Session Total (Current session)"/> attribute.

## Run the campaign

:::note
The `SUMMER2023` coupon code is already created in the demo campaign.
:::

To run the campaign, use the following payload sent to the Integration API's [Update customer session][cs] endpoint:

<Tabs
  defaultValue="req"
  values={[
    {label: '🚀 Request', value: 'req'},
    {label: '✅ Response', value: 'res'},
  ]}>

<TabItem value="req">

To trigger the rule, we must:
1. Line 19: Add the valid coupon code.

```json title="Sending a session update" {19} showLineNumbers
CURL -X PUT https://mycompany.europe-west1.talon.one/v2/customer_sessions/my_session_id -d
'{
  "customerSession": {
    "profileId": "{{Integration_id}}",
    "state": "open",
    "cartItems": [
      {
        "name": "ProductA",
        "sku": "sku-00001",
        "quantity": 1,
        "price": 233,
        "Category": "",
        "weight": 0,
        "position": 0,
        "attributes": {}
      }
    ],
    "couponCodes": [
      "SUMMER2023"
    ],
    "referralCode": "",
    "attributes": {},
    "additionalCosts": {}
  },
  "responseContent": []
}'
```
</TabItem>
<TabItem value="res">

We receive this response showing our two effects in the `effects` array:

1. Line 10: The `acceptCoupon` effect meaning our code is valid.
1. Line 21: The `setDiscount` effect meaning a 30% discount representing 69.9USD off the original session value must be applied.

```json title="Response" {10,21} showLineNumbers
{
  "createdCoupons": [],
  "createdReferrals": [],
  "effects": [
    {
      "campaignId": 9,
      "rulesetId": 8,
      "ruleIndex": 0,
      "ruleName": "30% off with coupon code",
      "effectType": "acceptCoupon",
      "triggeredByCoupon": 1,
      "props": {
        "value": "SUMMER2023"
      }
    },
    {
      "campaignId": 9,
      "rulesetId": 8,
      "ruleIndex": 0,
      "ruleName": "30% off with coupon code",
      "effectType": "setDiscount",
      "triggeredByCoupon": 1,
      "props": {
        "name": "30% off",
        "value": 69.9
      }
    }
  ]
}
```

</TabItem>
</Tabs>

:::tip Key Takeaways

- Checking if a coupon is valid is done with the [Coupon code is valid condition](/docs/product/rules/conditions/available-conditions.md#coupon-conditions).
- Coupons are created inside campaigns.
- The **Coupon code is valid** condition also automatically redeems all valid coupons in the session when the session **closes**.
- Setting the state of a session and adding a coupon code is done via the [Update customer session][cs] endpoint.

:::

## Related pages

- [Manage coupons](/docs/product/campaigns/coupons/manage-coupons.md)
- [Use conditions](/docs/product/rules/conditions/overview.md) and [effects](/docs/product/rules/effects/overview.md)

[cs]: /integration-api#tag/Customer-sessions/operation/updateCustomerSessionV2
