# 20% off when session value >200

Let's create a [promotion rule](/docs/product/rules/overview.md#promotion-rules) that provides a **20% discount** to every customer whose session value reaches $200.

This tutorial builds upon the [Always trigger a discount](/docs/product/tutorials/sample-campaigns/always-trigger-discount.md) tutorial,
where we learned how to set up a rule that always triggers. In this tutorial let's create
our first condition to ensure the discount is only applied to customer sessions whose
value exceeds 200USD.

:::note
The currency for this example is USD. The currency can be edited in
the [details](/docs/product/applications/create-and-manage-applications.md#edit-the-details-of-an-application) of your Application.
:::

## Create the conditional discount promotion

In the current scenario, let's use one rule and name it `20% off with basket value >200`.

### 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 **Check attribute value**.

   This condition allows you to check the value of an attribute against another value, or another attribute.
1. Click <Attribute name="Customer Name (customer profile)" type="custom" /> to replace it.
1. Search for <Attribute name="Session Total (Current Session)"/> and select it.
1. Replace **is equal to** with **is greater than**.
1. In the field right of **is equal to**, type `200` and press enter.

This condition means that we are now checking the value of the <Attribute name="Session Total (Current Session)"/> attribute
and if this value is greater than $200, this condition is true and Talon.One triggers the discount effect.

### Effect

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

1. Set the **Name** to something descriptive, such as `20% off`.
1. Set the **Discount value** to <Attribute name="[Session.Total]"/>`*20%`:
   1. Click **Add an attribute** (  ).
   1. Search for the <Attribute name="Session Total (Current Session)"/> attribute and select it.
   1. Back in the **Discount value** field, type `* 20%` to complete the discount value.

As in the previous tutorial, we calculate the discount value using the same **Session total** attribute.

**Discount session total**: **Name** is `20% off` and **Discount value** is <Attribute name="[Session.Total]"/>`*20%`.

## Run the campaign

To run the campaign, use the following payload sent to the Integration API's
[Update customer session](/integration-api#tag/Customer-sessions/operation/updateCustomerSessionV2) endpoint:

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

<TabItem value="req">

To trigger the rule, the session value must be greater than 200, which is the sum
of all cart items. In this case, let's share one item for 233USD.

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

We receive this response showing our only effect in the `effects` array:
a 20% discount representing 46.6USD off the original session value.

```json title="Response" {6-14} showLineNumbers
{
  "createdCoupons": [],
  "createdReferrals": [],
  "effects": [
    {
      "campaignId": 10,
      "rulesetId": 16,
      "ruleIndex": 0,
      "ruleName": "20% off with basket value >200",
      "effectType": "setDiscount",
      "props": {
        "name": "20% off",
        "value": 46.6
      }
    }
  ]
}
```

</TabItem>
</Tabs>

:::tip Key Takeaways
- Attributes can be used in effects, but also in conditions.
- For more control, we can check for specific [events](/docs/dev/concepts/entities/events.md)
  to trigger effects at specific moments in the life cycle of the customer session.
- You can use several conditions in one rule.
- By default, when using several conditions, all of them must be true for the effects to be applied.
:::

## Related pages

- [Cart item filters](/docs/product/rules/cart-item-filters/overview.md)
- [Use conditions](/docs/product/rules/conditions/overview.md) and [effects](/docs/product/rules/effects/overview.md)
