Discounts & Promotions
Create and manage discount codes and promotional campaigns.
Overview
The Discounts API lets you create, validate, and manage discount codes. Build promotional campaigns, loyalty rewards, or automated discount systems.
List Discounts
curl -X GET https://api.whatalo.com/v1/discounts \
-H "X-API-Key: wk_live_your_key_here"Required scope: read:discounts
Create a Discount
curl -X POST https://api.whatalo.com/v1/discounts \
-H "X-API-Key: wk_live_your_key_here" \
-H "Content-Type: application/json" \
-d '{
"code": "SAVE20",
"type": "percentage",
"value": 20,
"min_order_amount": 5000,
"max_uses": 100,
"starts_at": "2026-03-15T00:00:00Z",
"expires_at": "2026-04-15T23:59:59Z"
}'Required scope: write:discounts
Discount types: percentage | fixed_amount
Update a Discount
curl -X PATCH https://api.whatalo.com/v1/discounts/disc_abc123 \
-H "X-API-Key: wk_live_your_key_here" \
-H "Content-Type: application/json" \
-d '{
"max_uses": 200
}'Delete a Discount
curl -X DELETE https://api.whatalo.com/v1/discounts/disc_abc123 \
-H "X-API-Key: wk_live_your_key_here"Validate a Discount
Check if a discount code is valid before applying it:
curl -X POST https://api.whatalo.com/v1/discounts/validate \
-H "X-API-Key: wk_live_your_key_here" \
-H "Content-Type: application/json" \
-d '{
"code": "SAVE20",
"order_total": 7500
}'Response (valid):
{
"data": {
"valid": true,
"discount_amount": 1500
}
}Response (invalid):
{
"data": {
"valid": false,
"discount_amount": 0,
"reason": "Minimum order amount not reached"
}
}Common Patterns
Time-Limited Flash Sale
async function createFlashSale(hours, discountPercent) {
const now = new Date();
const expires = new Date(now.getTime() + hours * 60 * 60 * 1000);
const res = await fetch('https://api.whatalo.com/v1/discounts', {
method: 'POST',
headers: {
'X-API-Key': API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
code: `FLASH${discountPercent}`,
type: 'percentage',
value: discountPercent,
starts_at: now.toISOString(),
expires_at: expires.toISOString(),
max_uses: 50
})
});
if (!res.ok) {
throw new Error(`Failed to create flash sale: ${res.status}`);
}
return res.json();
}Single-Use Loyalty Reward
async function createLoyaltyCode(customerId, rewardAmount) {
const code = `LOYALTY-${customerId}-${Date.now()}`;
const res = await fetch('https://api.whatalo.com/v1/discounts', {
method: 'POST',
headers: {
'X-API-Key': API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
code,
type: 'fixed_amount',
value: rewardAmount,
max_uses: 1
})
});
if (!res.ok) {
throw new Error(`Failed to create loyalty code: ${res.status}`);
}
return res.json();
}