30% off with a coupon code
Prerequisites
- Create your Integration API key.
- If you haven't done so already, fork our Sample Campaigns collection in Postman:
- In the Campaign Manager, open the EASY-COUPON: 30% off with coupon code demo campaign and click Activate Campaign.
- Open the Rule Builder to get some context.
Let's create a promotion rule 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 Creating a discount based on session value tutorial, where we learned how to set up a rule triggering on certain events.
Creating 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. In our case we need the following condition:
- Click Add condition and select Coupon code is valid.
This condition allows you to check whether the coupon code(s) 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.
Effect
Let's set the Discount session total effect:
- Set the Name to something descriptive, such as
30% off
. - Set the Discount value to [Session.Total]
*30%
.
As in the previous tutorials, we calculate the discount value using the same Session Total (Current session) attribute.
Running the campaign
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 endpoint:
- 🚀 Request
- ✅ Response
To trigger the rule, we must:
- Line 19: Add the valid coupon code.
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": []
}'
We receive this response showing our two effects in the effects
array:
- Line 10: The
acceptCoupon
effect meaning our code is valid. - Line 21: The
setDiscount
effect meaning a 30% discount representing 69.9USD off the original session value must be applied.
{
"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
}
}
]
}
- Checking if a coupon is valid is done with the Coupon code is valid condition.
- 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 endpoint.