Getting Data out of Klaviyo

read
Last updated at:

Overview

Generally, when thinking about exporting data from Klaviyo data and syncing into another system, it helps to first understand Klaviyo’s data model, i.e., what data Klaviyo collects and how it is organized. For more on this topic see our Data Model.

The most commonly requested data object to export from Klaviyo are Metrics. Metrics are actions that are represented as timestamped records that include JSON-formatted payloads. They may contain an unlimited quantity of attribute-value pairs, optionally including arrays. Klaviyo automatically records Metrics for email, push, or SMS-related events such as “Received Email," “Opened Email," “Clicked Email," and more. Additional illustrative objects that may be exported include Profiles, Lists, and Unsubscribes.

How to Export Data

Klaviyo exposes data for export through several REST APIs associated with these data objects. Developers can use these to extract information, optionally using parameters to refine the information returned. As an example, a simple curl request to retrieve a list of each unique metric observed in the account via the Klaviyo Metrics API would look like this:

curl https://a.klaviyo.com/api/v1/metrics -G \
  -d api_key=api_key

The GET call returns a JSON object with all the fields of the specified dataset as a reply. In this illustrative example, the account has two unique metrics. The resulting JSON might look like:

{
  "end": 2,
  "object": "$list",
  "page_size": 50,
  "start": 0,
  "total": 3,
  "data": [
    {
      "updated": "2019-02-05 17:31:37",
      "name": "Active on Site",
      "created": "2019-02-05 17:31:37",
      "object": "metric",
      "id": "H7wi5R",
      "integration": {
        "category": "API",
        "object": "integration",
        "id": "7FtS4J",
        "name": "API"
      }
    },
    {
      "updated": "2019-02-05 17:31:37",
      "name": "Viewed Product",
      "created": "2019-02-05 17:31:37",
      "object": "metric",
      "id": "JgV8XH",
      "integration": {
        "category": "API",
        "object": "integration",
        "id": "7FtS4J",
        "name": "API"
      }
    },
    {
      "updated": "2019-10-01 02:57:11",
      "name": "Received Email",
      "created": "2019-10-01 02:57:11",
      "object": "metric",
      "id": "QhG7U2",
      "integration": {
        "category": "Internal",
        "object": "integration",
        "id": "0rG4eQ",
        "name": "Klaviyo"
      }
    }
  ]
}

Integrating Klaviyo with a Data Warehouse

Given this background, the general process of integrating Klaviyo with a data warehouse or internal system is as follows:

Step Description
Specify data to extract

Document the data objects and any filtering criteria that you want to apply when extracting data from Klaviyo. For example, if you are interested in syncing Klaviyo-originated metrics into another system, you could reflect this as follows:

Data objects: Metrics
Filtering criteria: All Metrics where “integration.name” equals “Klaviyo”

Test and validate API requests

After documenting the data that should be extracted, we recommend identifying the Klaviyo API endpoints that return the desired data and using Klaviyo’s sample API requests to fetch and validate the data, then define the logical steps to automate this. Using the example above, it might look like this:

Step 1: GET request to https://a.klaviyo.com/api/v1/metrics in order to get a list of all unique metrics.
Step 2: GET request to https://a.klaviyo.com/api/v1/metric/{metric_id}/export for each metric_id of interest

Map source data to destination Once you know the data that you want to extract and how to extract it, you must map Klaviyo’s data structure into your data warehouse or other business system. Klaviyo’s APIs return JSON formatted data, so if your warehouse or other business system requires another format, you may need to manipulate the output to conform to the expectations of the destination.
Build ETL (or use a pre-built connector)

Once you have specs for extracting data and mapping it to your target destination, the next step is to author the code that will automate the extract, transfer, and load (ETL) logic. You may benefit from using an open-source tool such as a Singer tap to achieve this.

If you prefer to avoid this step, you may opt for a tool with which Klaviyo has a pre-built integration such as Segment.com, Stitch Data, or Fivetran.

Perform QA Finally, having automated the ETL, you will want to validate that the data flows through as expected. 
x
Was this article helpful?
2 out of 10 found this helpful