# Always trigger a discount

> 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 always provides a **10% discount** to every customer.

Let's cover the logic of this campaign and trigger it with an API request
to simulate what the integration layer will do.

## Create the discount promotion

The logic of a campaign is always defined by its [rules](/docs/product/rules/overview.md). A
promotion rule typically has at least one **condition** and one **effect**. The effect represents
the result of the campaign for individual customers.

In the current scenario, let's use one rule and name it `Always 10% off`.

### Condition

Talon.One offers many [conditions](/docs/product/rules/conditions/available-conditions.md),
but in our case, we don't need any because we want to offer a discount **always**.

To always trigger the effects of a rule, click **Always Trigger Effects**. By _always_,
Talon.One means _whenever a customer updates their shopping cart_, for example by adding
an item.

### Effect

Talon.One also offers many [effects][eff]
and even allows you to create your own.
In this scenario, we need the [**Discount session total**](/docs/product/rules/effects/use-effects.md#discount-session-total) effect:

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

In our case, we calculate the discount value using an
[**attribute**](/docs/dev/concepts/attributes.md). Attributes represent any data stored
inside Talon.One. Attributes can be calculated by Talon.One, like a session value, or can
come from the integration layer.

The **session total** attribute represents the **value of the shopping cart** for
**any session**. We multiply this by 10% to discount it.

## Run the 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">

We can send any session update. The rule will always trigger. In this case, we share
a session that contains one cart item. It is defined in the `cartItems` array on line 6.

```json title="Sending a session update" {} showLineNumbers
CURL -X PUT https://mycompany.europe-west1.talon.one/v2/customer_sessions/my_session_id -d
'{
  "customerSession": {
    "profileId": "TN6329YKC8",
    "state": "closed",
    "cartItems": [
      {
        "name": "ProductA",
        "sku": "sku-00001",
        "quantity": 1,
        "price": 100,
        "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 10% discount representing 10USD off the original item (10% off 100USD).

```json title="Response" {6-14} showLineNumbers
{
  "createdCoupons": [],
  "createdReferrals": [],
  "effects": [
    {
      "campaignId": 11,
      "rulesetId": 10,
      "ruleIndex": 0,
      "ruleName": "Always 10% off",
      "effectType": "setDiscount",
      "props": {
        "name": "10% off",
        "value": 10.0
      }
    }
  ]
}
```

</TabItem>
</Tabs>

:::tip Key Takeaways

- Promotion rules are defined by conditions and effects.

  - A condition is what triggers a promotion, such as _a customer created their account_.
  - An effect is what your promotion does, for example discounting a session, giving loyalty points, etc. See [effects][eff].

- You can use attributes in your effects to operate on data inside Talon.One.
- The value of the shopping cart is represented by the **Session Total** attribute.
- Trigger the rules by sending a session that satisfies the rule's conditions.
- Send a session update with the [Update customer session][cs] endpoint.

:::

## Related pages

- [Update customer session endpoint][cs]
- [Available conditions](/docs/product/rules/conditions/available-conditions.md) and [effects][eff]

[cs]: /integration-api#tag/Customer-sessions/operation/updateCustomerSessionV2
[eff]: /docs/product/rules/effects/overview.md
