Create a campaign using structured rulesets Beta
This tutorial describes how to use structured rulesets to create and set up a campaign programmatically.
These rulesets include blocks, which are structured JSON objects that function in the same way as rules in the Campaign Manager. Ruleset blocks represent Rule Builder conditions and effects and can be used to define the logic of your campaigns.
In this tutorial, the ruleset for the campaign contains one promotion rule. This rule targets the cart and gives a 10% discount if a coupon code is valid.
Prerequisites
- You have created an Application.
- You have created a Management API key.
- You have not enabled Campaign staging and revisions for your Application. If this feature is enabled, you can't update the campaign programmatically.
Create the campaign and ruleset
Create a campaign
Use the Create campaign
endpoint to programmatically create a campaign in your Application. Since the rule we're
creating checks a coupon code, we must set the coupons feature
when creating the campaign. We also set a limit
of 1000 to define the number of coupons that can be created.
- You can also create a campaign in the Campaign Manager and follow the next steps of this tutorial to create a ruleset for it.
- The
stateis always set todisabledfor new campaigns, as a guardrail against unintended deployment.
Replace the placeholder values as follows:
YOUR_DEPLOYMENT_URLis the base URL of your Talon.One deployment, for example,mycompany.europe-west1.talon.one.YOUR_APPLICATION_IDis the ID of your Application.YOUR_API_KEYis your Management API key.
Use curl or a similar tool to send the following request:
curl https://YOUR_DEPLOYMENT_URL/v1/applications/YOUR_APPLICATION_ID/campaigns \
-X POST \
-H "Authorization: ManagementKey-v1 YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "10% off campaign",
"description": "Gives a 10% discount on the cart.",
"state": "disabled",
"features": [
"coupons"
],
"tags": [
"10% off"
],
"limits": [
{
"action": "createCoupon",
"limit": 1000,
"period": "yearly",
"entities": [
"Coupon"
]
}
]
}'
Example response:
{
"id": 5842,
"created": "2026-10-27T16:14:57.191873233Z",
"applicationId": 831,
"userId": 474,
"name": "10% off campaign",
"description": "Gives a 10% discount on the cart.",
"attributes": {},
"state": "disabled",
"tags": [
"10% off"
],
"features": [
"coupons"
],
"limits": [
{
"action": "createCoupon",
"limit": 1000,
"period": "yearly",
"entities": [
"Coupon"
]
}
]
}
Save the value of the id provided in the response, in our example 5842 . This is the ID of the new campaign.
You'll need it to replace the YOUR_CAMPAIGN_ID placeholder in the following steps.
Create a ruleset
Use the Create ruleset (V2) endpoint to create a ruleset for the campaign.
The ruleset contains one promotion rule with one condition and one effect, so we'll use the following blocks:
- The
checkCouponblock to represent the Coupon code is valid condition. - The
awardDiscountblock to represent the Discount session total effect.
The checkCoupon block includes the following value:
redeemis set totrue, meaning that if the coupon code is valid, it is automatically redeemed when the rule is triggered.
The awardDiscount block includes the following values:
valueis the expression{{$Session.CartItemTotal * 0.1}}, which means 10% of the cart total, excluding additional costs such as shipping.partialis set tofalse, which means the full discount value is applied, regardless of the campaign budget.target.typeis set tocart, so the discount applies to the cart as a single unit.
Replace the placeholder values as follows:
YOUR_DEPLOYMENT_URLis the base URL of your Talon.One deployment, for example,mycompany.europe-west1.talon.one.YOUR_APPLICATION_IDis the ID of your Application.YOUR_CAMPAIGN_IDis the ID of the campaign you created. Use theidvalue you saved from the response in the previous step.YOUR_API_KEYis your Management API key.
Send the following request:
curl https://YOUR_DEPLOYMENT_URL/v2/applications/YOUR_APPLICATION_ID/campaigns/YOUR_CAMPAIGN_ID/rulesets \
-X POST \
-H "Authorization: ManagementKey-v1 YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"promotionRules": [
{
"title": "10% off the cart",
"blocks": [
{
"type": "checkCoupon",
"redeem": true
},
{
"type": "awardDiscount",
"name": "10% off",
"value": "{{$Session.CartItemTotal * 0.1}}",
"partial": false,
"target": {
"type": "cart"
}
}
]
}
]
}'
Example response:
{
"id": 12582,
"created": "2026-10-27T16:34:23.018507576Z",
"userId": 474,
"campaignId": 5842,
"promotionRules": [
{
"title": "10% off the cart",
"blocks": [
{
"id": "b3ba0c77-70e3-57e3-8306-895c33063eaa",
"type": "checkCoupon",
"tags": [
"condition",
"coupon"
],
"redeem": true
},
{
"id": "beb7c6e6-91e0-56fe-aabb-5246fc6292fd",
"type": "awardDiscount",
"tags": [
"effect",
"discount"
],
"name": "10% off",
"value": "{{$Session.CartItemTotal * 0.1}}",
"partial": false,
"target": {
"type": "cart"
}
}
]
}
],
"selectors": []
}
Save the value of the id provided in the response, in our example 12582. This is the ID of the ruleset.
You'll need it to replace the YOUR_RULESET_ID placeholder in the following steps.
Update the campaign
You have now created the new ruleset, but it has not been added to your campaign yet. Use the Update campaign endpoint to set it as the active ruleset of the campaign, and to activate the campaign programmatically.
In the request, we set the campaign state to enabled to activate the campaign, and add
a value for activeRulesetId to add the new ruleset to the campaign.
Replace the placeholder values as follows:
YOUR_DEPLOYMENT_URLis the base URL of your Talon.One deployment, for example,mycompany.europe-west1.talon.one.YOUR_APPLICATION_IDis the ID of your Application.YOUR_CAMPAIGN_IDis the ID of the campaign you created.YOUR_API_KEYis your Management API key.YOUR_RULESET_IDis the ID of the ruleset. Use theidvalue you saved from the response in the previous step.
Send the following request:
curl https://YOUR_DEPLOYMENT_URL/v1/applications/YOUR_APPLICATION_ID/campaigns/YOUR_CAMPAIGN_ID \
-X PUT \
-H "Authorization: ManagementKey-v1 YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "10% off campaign",
"state": "enabled",
"activeRulesetId": YOUR_RULESET_ID,
"features": [
"coupons"
],
"tags": [
"10% off"
],
"limits": [
{
"action": "createCoupon",
"limit": 1000,
"period": "yearly",
"entities": [
"Coupon"
]
}
]
}'
Example response:
{
"id": 5842,
"created": "2026-10-27T16:14:57.191873Z",
"applicationId": 831,
"userId": 474,
"name": "10% off campaign",
"attributes": {},
"state": "enabled",
"tags": [
"10% off"
],
"features": [
"coupons"
],
"limits": [
{
"action": "createCoupon",
"limit": 1000,
"period": "yearly",
"entities": [
"Coupon"
]
}
]
}
Verify the result
Open your Application to check that the campaign exists in the Campaigns page. The new campaign is in the Running state and contains the promotion rule you created, which gives a 10% discount when the coupon code is valid.
To modify the rules or add new rules to your new campaign programmatically, follow the steps above for creating a ruleset and updating the campaign. You can also create and manage rules for the new campaign in the Campaign Manager.