Iterable to Redshift

Need to get Iterable data to your warehouse? You’ve come to the right place! This page will give you the tools you need to do just that. (If this manual process sounds onerous, check out Stitch, which can do all the heavy lifting for you in just a few clicks.)

Collecting Iterable Data

The first step for getting your Iterable data into Redshift is collecting that data from Iterable’s servers. You can do this using Webhooks. Documentation for Iterable Webhooks integration can be found here.

Data from Iterable is retrieved via user-defined HTTP callbacks.  Step one is to set up the webhook in your Iterable account. You will provide a url to send the data to and design your script to listen on this URL.

Sample Iterable Data

Once you’ve set up HTTP endpoints, Iterable will begin sending data via the POST request method.  Data will be enclosed in the body of the request in JSON format.  Below is a sample of what an inbound webhook with email_open data looks like when it comes from Iterable.

{
   "email": "jeremy+test@iterable.com",
   "eventName": "emailOpen",
   "dataFields": {
      "userAgent": "Mozilla/5.0 (Windows NT 5.1; rv:11.0) Gecko Firefox/11.0 (via ggpht.com GoogleImageProxy)",
      "ip": "66.249.84.204",
      "templateId": 79190,
      "device": "Gmail",
      "email": "jeremy+test@iterable.com",
      "createdAt": "2016-12-02 18:51:45 +00:00",
      "campaignId": 49313,
      "messageId": "210badf49fe54f2591d64ad0d055f4fb",
      "emailSubject": "My Subject",
      "campaignName": "Testing attribution",
      "workflowId": null,
      "workflowName": null,
      "templateName": "Attribution to any in time range test",
      "channelId": 3420,
      "messageTypeId": 3866,
      "experimentId": null,
      "emailId": "c49313:t79190:jeremy+test@iterable.com"
   }
}

Preparing Iterable Data for Redshift

With the JSON in hand, you now need to map all those data fields into a schema that can be inserted into your Redshift database. This means that, for each value in the response, you need to identify a predefined data type (i.e. INTEGER, DATETIME, etc.) and build a table that can receive them.

The Iterable documentation can give you a good sense of what fields will be provided by each endpoint, along with their corresponding data types. Once you have identified all of the columns you will want to insert, use the CREATE TABLE statement in Redshift to define a table that can receive all of this data.

Inserting Iterable Data into Redshift

It may seem like the easiest way to add your data is to build tried-and-true INSERT statements that add data to your Redshift table row-by-row. If you have any experience with SQL, this will be your gut reaction and it will work but isn’t the most efficient way to get the job done.

Redshift actually offers some good documentation for how to best bulk insert data into new tables. The COPY command is particularly useful for this task, as it allows you to insert multiple rows without needing to build individual INSERT statements for each row.

If you cannot use COPY, it might help to use PREPARE to create a prepared INSERT statement, and then use EXECUTE as many times as required. This avoids some of the overhead of repeatedly parsing and planning INSERT.

Keeping Data Up-To-Date

So what’s next? You’ve built a script that collects data from Iterable and moves it into Redshift.  What happens when Iterable sends a data type that your script doesn’t recognize?  It’s also important to consider the situation where an entry in Redshift needs to be updated to a new value. Once you’ve build in that functionality, you can set your script up as a cron job or continuous loop to keep pulling new data as it appears.

Other Data Warehouse Options

Redshift is totally awesome, but sometimes you need to start smaller or optimize for different things. In this case, many people choose to get started with Postgres, which is an open source RDBMS that uses nearly identical SQL syntax to Redshift. If you’re interested in seeing the relevant steps for loading this data into Postgres, check out Iterable to Postgres

Easier and Faster Alternatives

If you have all the skills necessary to go through this process, chances are building and maintaining a script like this isn’t a very high-leverage use of your time.

Thankfully, products like Stitch were built to solve this problem automatically. With just a few clicks, Stitch starts extracting your Iterable data via the webhook API, structuring it in a way that is optimized for analysis, and inserting that data into your Redshift data warehouse.