You can generate a unique Shopcada discount code from Klaviyo and include it in your Klaviyo email content.
This is useful for campaigns where each customer should receive a unique discount code, such as welcome offers, birthday rewards, win-back campaigns, and targeted loyalty promotions.
What’s New
You can now lock a generated discount code to a specific customer account by adding the lock_discount property in the Klaviyo webhook payload.
When lock_discount is set to true, the generated discount code can only be redeemed by the customer linked to the email address in the webhook request.
This helps prevent customers from sharing discount codes with others.
This document cover:
Prerequisites
Before setting up the Klaviyo webhook, make sure you have completed the following:
-
Create the discount in Shopcada.
-
Take note of the Discount ID.
-
Enable Require discount code to activate this discount in the discount configuration.
-
Make sure the customer email used in Klaviyo matches the customer email in Shopcada if you are using locked discount codes.
Step 2: Set the Destination URL
Set the Destination URL as:
https://<your-domain-name>/api/plugin/klaviyo/discount
Replace <your-domain-name> with your actual store domain.
Example:
https://testingsite.com/api/plugin/klaviyo/discount
Step 3: Set the JSON Body
Use the following JSON body:
{
"discount_id": 4,
"expire_in": 2,
"profile_id": "{{ person.KlaviyoID }}",
"email": "{{ person.email }}"
}
JSON Field Definition
| Field | Description |
|---|---|
discount_id |
The Discount ID created in Shopcada. This can be found at the top of the discount configuration page. |
expire_in |
Number of days before the generated discount code expires. The countdown starts from the time the code is generated. |
profile_id |
Klaviyo profile ID. Copy this exactly as {{ person.KlaviyoID }}. |
email |
Customer email address from Klaviyo. Copy this exactly as {{ person.email }}. |
Note: Remove any square brackets when entering the values for discount_id and expire_in.
Step 4: Preview and Send Test Request
After setting up the webhook:
-
Scroll up slightly.
-
Click Preview above the Destination URL field.
-
In the pop-up, click Send Test Request.
This helps confirm that the webhook can successfully generate the discount code.
Step 5: Add a Time Delay
Add a 1 to 5 minute time delay between the Webhook action and Email action.
This gives the generated discount code enough time to sync back to Klaviyo before the email is sent.
Step 6: Add the Discount Code to Email Content
In your Klaviyo email:
-
Click Add personalization.
-
Select or enter the discount code variable.
-
Add the following token into your email content:
{{ person|lookup:"discount_code"|default:'' }}
This token will display the unique discount code generated by the webhook.
Step 7: Test the Full Flow
Before activating the flow, run a full test to confirm:
-
The webhook generates the discount code successfully.
-
The discount code appears in the Klaviyo email.
-
The discount code can be applied on Shopcada.
-
If
lock_discountis enabled, only the intended customer can redeem the code.
Optional: Lock Discount Code to Customer
To make the generated discount code usable only by the intended customer, add the lock_discount property and set it to true.
Example JSON Body with Locked Discount
{
"discount_id": 4,
"expire_in": 2,
"profile_id": "{{ person.KlaviyoID }}",
"email": "{{ person.email }}",
"lock_discount": true
}
How Locked Discount Works
When lock_discount is set to true:
-
Shopcada will look for the customer account using the email address passed from Klaviyo.
-
The generated unique discount code will be linked to that customer account.
-
The discount code can only be redeemed by the linked customer.
-
Other customers will not be able to use the same discount code.
-
If no Shopcada customer account is found for the email address, the discount code will not be generated as a shareable code.
Use this option when the promotion is intended for one customer only, such as member rewards, birthday rewards, private offers, and retention campaigns.
Important Notes
-
discount_id,expire_in,profile_id, andemailare required fields. -
lock_discountis optional. -
If
lock_discountis not included, the default value isfalse. -
When
lock_discountisfalse, the generated code is not locked to a customer account. -
When
lock_discountistrue, the customer email must match a Shopcada customer account. -
Always test your flow before sending it to customers.

