Delivering Targeted Coupons
ai12z enables you to reward users with targeted, one-time coupons as part of your automated chat and support flows—perfect for returns, high-value purchases, loyalty milestones, and more. This guide shows you how to set up targeted coupon delivery by integrating your e-commerce or CDP system (e.g., Shopify, Klaviyo, Salesforce, Adobe, custom) with ai12z’s Custom Integrations.
1. Prerequisites
- Access to the ai12z portal and permissions to add Custom Integrations.
- API credentials for your e-commerce/CDP platform (e.g., Shopify admin API, Klaviyo private key).
- The platform must support creating or fetching coupon codes via API.
2. Common Coupon Delivery Scenarios
- After a return or support case (“Thanks for your patience—here’s a 10% off coupon”)
- For loyalty/rewards users (“You’ve hit Gold! Enjoy this exclusive code”)
- Based on user actions (e.g., leaving a review, referring a friend)
- Manual triggers by live agents in chat
3. Integration Workflow Overview
graph TD
A[User Triggers Coupon Flow<br>(e.g. completes a return)] --> B[ai12z Reasoning Engine]
B --> C[Custom Integration]
C --> D[E-commerce/CDP Coupon API]
D --> E[Coupon Code]
E --> F[Bot Responds in Chat<br>with Personalized Coupon]
4. Step-by-Step Setup
A. Set Up Coupon Generation in Your Platform
Example: Shopify
- Create a Price Rule (defines the discount logic).
- Create a Discount Code (actual code to give to user).
Example API Call to Generate a Code:
import requests
SHOPIFY_DOMAIN = "yourstore.myshopify.com"
API_KEY = "your-api-key"
PASSWORD = "your-api-password"
# Step 1: Create price rule
pricerule_resp = requests.post(
f"https://{API_KEY}:{PASSWORD}@{SHOPIFY_DOMAIN}/admin/api/2024-04/price_rules.json",
json={
"price_rule": {
"title": "ReturnReward",
"target_type": "line_item",
"target_selection": "all",
"allocation_method": "across",
"value_type": "percentage",
"value": "-10.0", # 10% off
"customer_selection": "all",
"starts_at": "2025-07-15T00:00:00-04:00"
}
}
)
pricerule_id = pricerule_resp.json()["price_rule"]["id"]
# Step 2: Create discount code
discount_resp = requests.post(
f"https://{API_KEY}:{PASSWORD}@{SHOPIFY_DOMAIN}/admin/api/2024-04/price_rules/{pricerule_id}/discount_codes.json",
json={
"discount_code": {"code": "THANKS10-" + "XYZ123"}
}
)
coupon_code = discount_resp.json()["discount_code"]["code"]
Tip: Most platforms (Klaviyo, Salesforce, Magento, WooCommerce, custom) offer similar endpoints for coupon code creation.
B. Create a Custom Integration in ai12z
-
Go to the ai12z portal > Integrations > Custom Integrations
-
Create New Integration
- Type: REST (or GraphQL, MCP if your backend supports it)
- Method: POST (for code creation), or GET (for code fetch)
- URL: Your coupon endpoint (e.g., Shopify’s API)
- Headers: Add your API keys/tokens as needed
- Parameters/body: Map
{attributes.user.email}or other context fields from the chat/session
Example: ai12z Integration Request Mapping
{
"price_rule": {
"title": "ReturnReward",
"customer_selection": "all",
"value_type": "percentage",
"value": "-10.0",
"starts_at": "{{ now | iso8601 }}"
}
}
- Use JSONata or direct mapping to pass chat context (like user email, name, loyalty status).
-
Test Integration
- Use the “Test” button in the portal to generate a test coupon and verify the response.
C. Surface the Coupon in the Chatbot Response
In your agent’s ReAct System Prompt:
You are a helpful assistant.
If a user completes a return or triggers a coupon scenario, call the "GenerateCoupon" integration and display the returned coupon code with a friendly message.
Always personalize your reply using `{attributes}`.
Example Chat Flow:
- User: “I’ve submitted my return, what next?”
- Bot: (Integration triggers, code generated)
“Thank you for your return! Here’s a 10% off coupon for your next order:
THANKS10-XYZ123”