Linking a Unique Discount Code on Klaviyo to Shopcada Discounts

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.


Prerequisites

Before setting up the Klaviyo webhook, make sure you have completed the following:

  1. Create the discount in Shopcada.

  2. Take note of the Discount ID.

  3. Enable Require discount code to activate this discount in the discount configuration.

  4. Make sure the customer email used in Klaviyo matches the customer email in Shopcada if you are using locked discount codes.


Setting Up on Klaviyo

Step 1: Add a Webhook Action

From your Klaviyo flow:

  1. Go to the left panel.

  2. Under Actions, drag and drop the Webhook action before the email action.

  3. Click Set up Webhook.

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:

  1. Scroll up slightly.

  2. Click Preview above the Destination URL field.

  3. 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:

  1. Click Add personalization.

  2. Select or enter the discount code variable.

  3. 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_discount is 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, and email are required fields.

  • lock_discount is optional.

  • If lock_discount is not included, the default value is false.

  • When lock_discount is false, the generated code is not locked to a customer account.

  • When lock_discount is true, the customer email must match a Shopcada customer account.

  • Always test your flow before sending it to customers.