Creating coupons via Klaviyo
In this tutorial, let's set up Klaviyo to automatically generate coupons inside Talon.One and add them to customer profiles in Klaviyo.
Let's imagine your website has a newsletter. When a customer subscribes to the newsletter, you want to send them a personal coupon.
To achieve this, we rely on webhooks and API endpoints:
- To send data from Klaviyo to Talon.One, we use Klaviyo's webhook functionality and Talon.One's Track event endpoint.
- To send data from Talon.One to Klaviyo, we use Talon.One's webhook functionality and Klaviyo's Create or Update Profile endpoint.
Talon.One requirements
- You are an Admin user.
- You have set up an Application.
- Your Application contains a running campaign with the Coupons feature enabled.
You can edit the default format of the coupon codes in the campaign's Settings section.
Klaviyo requirements
- You have enabled multi-factor authentication (MFA) for your account.
- Your user role is Manager, Admin, or Owner.
- You have created a list.
In this tutorial, we assume the list is named
Newsletter
.tipThe workflow described in this tutorial also works with segments.
Creating the API keys
To send data back and forth, we need access keys for Talon.One's Integration API and Klaviyo's Profiles API.
Integration API key
To create a generic Integration API key in Talon.One:
-
In your Application, click Settings > Integration API Keys.
-
Click Create API Key.
-
In the Create API Key drawer, select Production as the key type.
-
In Key name, type a name to identify the key.
-
In Key expiration date, select a date.
-
In Third-party integration, select No.
-
Click Create API Key.
-
Click to copy the key for use.
noteYou cannot view or copy the API key after closing the drawer. If you lose it, create another API key.
Profiles API key
To create a Profiles API key in Klaviyo, refer to the Klaviyo docs.
The key must have Read/Write access for the Profiles scope.
Creating and storing the coupon code
In the sections below, we create a workflow so that the following steps happen:
- Adding a customer to a newsletter list in Klaviyo triggers a flow with a webhook action.
- The webhook action calls Talon.One's Track event endpoint, providing the customer's profile ID.
- Registering the event in Talon.One triggers a rule that creates a coupon code for the customer.
- Creating the coupon triggers a custom webhook in Talon.One.
- The custom webhook calls Klaviyo's Create or Update Profile endpoint, providing the profile ID and the coupon code.
- The customer's profile is updated with the coupon code.
Creating the flow
To create a Klaviyo flow with a webhook action that calls Talon.One's Track event endpoint:
- In Klaviyo, open Flows and click Create flow.
- Click Build your own, type a name for the flow, and click Create flow.
- Select the Added to list trigger, choose the list you created, and save the trigger.
- On the left-side menu of the flow builder, click the Webhook action and drag it into your flow.
- Name the webhook and make the following settings:
-
Destination URL:
https://YOUR_DEPLOYMENT_URL/v2/events
, whereYOUR_DEPLOYMENT_URL
is the base URL of your Talon.One deployment, for example,mycompany.europe-west1.talon.one
. -
Headers:
Key Value Authorization ApiKey-v1 YOUR_API_KEY
, whereYOUR_API_KEY
is the Integration API key you created.Content-Type application/json
Accept application/json
-
JSON body:
{
"type": "klaviyoEvent",
"profileId": "{{ person.KlaviyoID|default:'' }}",
"attributes": {
"flowName": "newsletter"
}
}
-
Now, whenever a customer is added to your list, a request is sent to Talon.One's API.
The request includes the following:
- The type of the event (
klaviyoEvent
). - A unique ID of the current customer's profile in Klaviyo (
person.KlaviyoID
). This allows us to personalize the coupon code. - A custom attribute named
flowName
with the static valuenewsletter
. This allows us to uniquely identify the requests from this flow.
To register the event, both the event type and the custom attribute must exist in Talon.One, so let's create them.
Creating the custom attributes
To create the custom attributes required for your flow:
- In Talon.One, click Account > Tools > Attributes > Create Attribute.
- In Entity, select Event.
- In Event type, type
klaviyoEvent
. - In Type, select String.
- In API name, type
flowName
. - In Name, type
Flow name
. - Fill the other fields as needed and click Create Attribute.
This creates both the klaviyoEvent
event type and the flowName
attribute.
Creating the webhook
To create a webhook that calls Klaviyo's Create or Update Profile endpoint:
-
In the Campaign Manager, click Account > Tools > Webhooks and click Create Webhook.
-
In Properties, enter a name and select your Application.
-
Add the parameters to include in the request. In this tutorial, we use the following parameters:
Param type Param name string
CouponCode
string
CustomerProfileID
-
In Request, set Verb to
POST
. -
In URL, enter
https://a.klaviyo.com/api/profile-import/
. -
In Headers, click Add and define the following HTTP headers:
Authorization: Klaviyo-API-Key YOUR_KLAVIYO_API_KEY
, whereYOUR_KLAVIYO_API_KEY
is the API key you created.revision: 2024-10-15
. For more information about API revisions, see the Klaviyo docs.accept: application/json
content-type: application/json
-
In Payload, add the following request payload:
{
"data": {
"type": "profile",
"attributes": {
"properties": {
"t1_coupon": "${$CouponCode}"
}
},
"id": "${$CustomerProfileID}"
}
}tipTo learn more about accessing Talon.One attributes and including them in the webhook, see Using parameters in a webhook.
This webhook calls Klaviyo's API to store the coupon code in a custom profile property
named t1_coupon
. The property is created automatically when the endpoint is called.
Creating the rule
Now, let's bring it all together by creating a rule that generates the coupon code and stores it in Klaviyo:
What | Name | Properties |
---|---|---|
Condition | Check for event types and custom event values |
|
Effect 1 | Create coupon code |
|
Effect 2 | Webhooks |
|
When the matching event is registered, the rule is triggered, a coupon code is generated, and the custom webhook is triggered, which stores the coupon code in Klaviyo.
Next steps
Now that all of your newsletter subscribers have a personal coupon code, you can send them the code, for example, by creating an email campaign in Klaviyo.
To reference the coupon code in the email, use the following personalization tag: {{ person|lookup:"t1_coupon" }}
.