Skip to content
Last updated

Klaviyo Export Integration

Klaviyo is a digital marketing platform focused on email marketing automation for e-commerce businesses. Klaviyo offers an SMS and email marketing automation platform for e-commerce.

Using this integration and TD

  • You can add profiles to a Klaviyo member list.
  • You can remove profiles from Klaviyo member list

Prerequisites

  • Basic knowledge of Treasure Data, including the TD Toolbelt.
  • A Klaviyo account with a Private API access token.

API Information

Treasure Data uses the Campaigns API to direct Klaviyo to send email messages. The documentation on the Request Body of this API can be very helpful in setting up your email templates on Klaviyo.

Requirements and Limitations

  • To perform a "Remove Profiles" operation," your query must specify a profile_id column (case sensitive) whose data type is a string. If your query does not specify this column, then an error is returned, and the job fails.
  • To perform an "Add Profiles" operation, your query must specify a column named email (case sensitive) whose data type is string. If your query does not specify this column, then an error is returned, and the job fails.
  • If your query specifies a column named phone_number (case sensitive), then data from this field must follow the Accepted phone number formats for SMS in Klaviyo. Otherwise, an error is returned, and the job fails.

Obtain the Private API access token from Klaviyo Console

  1. Log in to the Klaviyo Dashboard.

  2. On the Settings tab select Create Private API Key.

  3. Copy the Private API key and store it in a secure location.

Obtain the List Name or List ID from the Klaviyo Console

  1. Log in to the Klaviyo Dashboard.
  2. On the left-hand side of the Dashboard, select Lists & Segments.
  3. From the Lists & Segments page, select the link for your list name.
  4. Copy the list_id from the URL of the list display page and store it in a secure location.

Use the TD Console to Create Your Connection

Create a New Connection

In Treasure Data, you must create and configure the data connection prior to running your query. As part of the data connection, you provide authentication to access the integration.

  1. Open TD Console.
  2. Navigate to Integrations Hub > Catalog.
  3. Search for Klaviyo and select Klaviyo Output Beta.
  4. Select Create Authentication.
  5. Enter your Klaviyo Private API key.
  6. Select Continue.
  7. Enter a name for your connection.
  8. Select Done.

Define your Query

To perform an "Add Profiles" operation, your query must specify a column named email (case sensitive) whose data type is string. If your query does not specify this column, then an error is returned, and the job fails.

To perform a "Remove Profiles" operation," your query must specify a profile_id column (case sensitive) whose data type is a string. If your query does not specify this column, then an error is returned, and the job fails.

  1. Complete the instructions in Creating a Destination Integration.

  2. Navigate to Data Workbench > Queries.

  3. Select a query for which you would like to export data.

  4. Run the query to validate the result set.

  5. Select Export Results.

  6. Select Use Existing Integration.

  7. Define any additional Export Results details. In your export integration content review the integration parameters.

  8. Select Done.

  9. Run your query.

  10. Validate that your data moved to the destination you specified.

Integration Parameters for Klaviyo

ParameterValuesDescription
Data operation- Add profiles - Remove profilesAdd or remove profiles from a Klaviyo list. Klaviyo's profile_id is required for the remove profiles operation. After removal, the profile will no longer receive marketing emails from this particular list.
Add to- List ID - List NameUsed to identify the Klaviyo list.
List ID or List Name value- List ID - List NameThe List ID or List Name that profiles will be added to.  If the "Add to" parameter has been set to List Name, and the name specified here does not exist in Klaviyo then a new list will be created with these values.
Wait Until The Operation Is Finished?True/FalseIf checked, the TD Console will wait until the operation is finished on Klaviyo side before continuing. If unchecked, the TD Console submits the task to Klaviyo and moves on.
The waiting time for operation completionMinimum: 300000 ms (5 minutes) Maximum: 86400000 ms (1 day)The time in milliseconds that TD Console will wait for the operation to complete.

Example Query

This query must include an email column.

SELECT email, col_a, col_b, col_c
FROM your_table;

This query requires a profile_id column.

SELECT profile_id FROM your_table;

(Optional) Schedule Query Export Jobs

You can use Scheduled Jobs with Result Export to periodically write the output result to a target destination that you specify.

Treasure Data's scheduler feature supports periodic query execution to achieve high availability.

When two specifications provide conflicting schedule specifications, the specification requesting to execute more often is followed while the other schedule specification is ignored.

For example, if the cron schedule is '0 0 1 * 1', then the 'day of month' specification and 'day of week' are discordant because the former specification requires it to run every first day of each month at midnight (00:00), while the latter specification requires it to run every Monday at midnight (00:00). The latter specification is followed.

Scheduling your Job Using TD Console

  1. Navigate to Data Workbench > Queries

  2. Create a new query or select an existing query.

  3. Next to Schedule, select None.

  4. In the drop-down, select one of the following schedule options:

    Drop-down ValueDescription
    Custom cron...Review Custom cron... details.
    @daily (midnight)Run once a day at midnight (00:00 am) in the specified time zone.
    @hourly (:00)Run every hour at 00 minutes.
    NoneNo schedule.

Custom cron... Details

Cron ValueDescription
0 * * * *Run once an hour.
0 0 * * *Run once a day at midnight.
0 0 1 * *Run once a month at midnight on the morning of the first day of the month.
""Create a job that has no scheduled run time.
 *    *    *    *    *
 -    -    -    -    -
 |    |    |    |    |
 |    |    |    |    +----- day of week (0 - 6) (Sunday=0)
 |    |    |    +---------- month (1 - 12)
 |    |    +--------------- day of month (1 - 31)
 |    +-------------------- hour (0 - 23)
 +------------------------- min (0 - 59)

The following named entries can be used:

  • Day of Week: sun, mon, tue, wed, thu, fri, sat.
  • Month: jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec.

A single space is required between each field. The values for each field can be composed of:

Field ValueExampleExample Description
A single value, within the limits displayed above for each field.
A wildcard '*' to indicate no restriction based on the field.'0 0 1 * *'Configures the schedule to run at midnight (00:00) on the first day of each month.
A range '2-5', indicating the range of accepted values for the field.'0 0 1-10 * *'Configures the schedule to run at midnight (00:00) on the first 10 days of each month.
A list of comma-separated values '2,3,4,5', indicating the list of accepted values for the field.0 0 1,11,21 * *'Configures the schedule to run at midnight (00:00) every 1st, 11th, and 21st day of each month.
A periodicity indicator '*/5' to express how often based on the field's valid range of values a schedule is allowed to run.'30 */2 1 * *'Configures the schedule to run on the 1st of every month, every 2 hours starting at 00:30. '0 0 */5 * *' configures the schedule to run at midnight (00:00) every 5 days starting on the 5th of each month.
A comma-separated list of any of the above except the '*' wildcard is also supported '2,*/5,8-10'.'0 0 5,*/10,25 * *'Configures the schedule to run at midnight (00:00) every 5th, 10th, 20th, and 25th day of each month.
  1. (Optional) You can delay the start time of a query by enabling the Delay execution.

Execute the Query

Save the query with a name and run, or just run the query. Upon successful completion of the query, the query result is automatically exported to the specified destination.

Scheduled jobs that continuously fail due to configuration errors may be disabled on the system side after several notifications.

(Optional) You can delay the start time of a query by enabling the Delay execution.

Optionally Configure Export Results in Workflow

Within Treasure Workflow, you can specify the use of this data connector to export data.

Learn more about using workflows to export data with the TD Toolbelt.

Example Workflow for Adding Profiles by List ID

_export:
  td:
    database: klaviyo_db

+klaviyo_export_task:
  td>: export_data.sql
  database: ${td.database}
  result_connection: new_created_klaviyo_auth
  result_settings:
    type: klaviyo
    api_token: api_token
    operation: add
    list_identify_type: id
    list_value: id_value
    wait_for_completion: true
    waiting_time_for_completion_millis:3600000

Example Workflow for Adding profiles by List Name

_export:
  td:
    database: klaviyo_db

+klaviyo_export_task:
  td>: export_data.sql
  database: ${td.database}
  result_connection: new_created_klaviyo_auth
  result_settings:
    type: klaviyo
    api_token: api_token
    operation: add
    list_identify_type: name
    list_value: name_value
    wait_for_completion: true
    waiting_time_for_completion_millis:3600000

Example Workflow for Removing Profiles by List ID

_export:
  td:
    database: klaviyo_db

+klaviyo_export_task:
  td>: export_data.sql
  database: ${td.database}
  result_connection: new_created_klaviyo_auth
  result_settings:
    type: klaviyo
    api_token: api_token
    operation: remove_profiles
    list_identify_type: id
    list_value: id_value

Example Workflow for Removing Profiles by List Name

_export:
  td:
    database: klaviyo_db

+klaviyo_export_task:
  td>: export_data.sql
  database: ${td.database}
  result_connection: new_created_klaviyo_auth
  result_settings:
    type: klaviyo
    api_token: api_token
    operation: remove_profiles
    list_identify_type: name
    list_value: name_value