Mailchimp to BigQuery

This page provides you with instructions on how to extract data from Mailchimp and load it into Google BigQuery. (If this manual process sounds onerous, check out Stitch, which can do all the heavy lifting for you in just a few clicks.)

What is Google BigQuery?

Google BigQuery is a data warehouse that delivers super-fast results from SQL queries, which it accomplishes using a powerful engine dubbed Dremel. With BigQuery, there's no spinning up (and down) clusters of machines as you work with your data. With all of that said, it's clear why some claim that BigQuery prioritizes querying over administration. It's super fast, and that's the reason why most folks use it.

Getting data out of Mailchimp

In order to get your MailChimp data into your data warehouse, you have to start by extracting it from MailChimp’s servers. You can do this using the MailChimp API, which is available to all MailChimp customers. Full API documentation can be accessed at this link

The tricky thing about Mailchimp is that it generates a LOT of data. Anytime you send an email or someone opens and reads one, you are generating data and that can add up very quickly. Depending on your needs, you may want to use Webhooks technology in order to continuously receive streaming updates of these events as they happen. Unfortunately, that means you’ll also need to build code on your end to receive this streaming data.

Mailchimp also offers a more durable API for syncing campaign information and stats that may be more what you’re looking for. Check out the docs through the lens of your use case to make the right call for you.

Sample Mailchimp data

The Mailchimp API returns JSON-formatted data. Below is an example of the kind of response you might see when querying the accounts endpoint.

HTTP/1.1 200 OK
{
 "account_id": "8d3a3db4d97663a9074efcc16",
 "account_name": "Freddie's Jokes",
 "contact": {
   "company": "Freddie's Jokes",
   "addr1": "675 Ponce De Leon Ave NE",
   "addr2": "Suite 5000",
   "city": "Atlanta",
   "state": "GA",
   "zip": "30308",
   "country": "US"
 },
 "last_login": "2015-09-15 14:25:37",
 "total_subscribers": 413,
 "_links": [
   {
     "rel": "self",
     "href": "https://usX.api.mailchimp.com/3.0/",
     "method": "GET",
     "targetSchema": "https://api.mailchimp.com/schema/3.0/Root.json"
   },
   {
     "rel": "lists",
     "href": "https://usX.api.mailchimp.com/3.0/lists",
     "method": "GET",
     "targetSchema": "https://api.mailchimp.com/schema/3.0/Lists/Collection.json",
     "schema": "https://api.mailchimp.com/schema/3.0/CollectionLinks/Lists.json"
   },
   {
     "rel": "reports",
     "href": "https://usX.api.mailchimp.com/3.0/reports",
     "method": "GET",
     "targetSchema": "https://api.mailchimp.com/schema/3.0/Reports/Collection.json",
     "schema": "https://api.mailchimp.com/schema/3.0/CollectionLinks/Reports.json"
   },
   {
     "rel": "conversations",
     "href": "https://usX.api.mailchimp.com/3.0/conversations",
     "method": "GET",
     "targetSchema": "https://api.mailchimp.com/schema/3.0/Conversations/Collection.json",
     "schema": "https://api.mailchimp.com/schema/3.0/CollectionLinks/Conversations.json"
   },
   {
     "rel": "campaigns",
     "href": "https://usX.api.mailchimp.com/3.0/campaigns",
     "method": "GET",
     "targetSchema": "https://api.mailchimp.com/schema/3.0/Campaigns/Collection.json",
     "schema": "https://api.mailchimp.com/schema/3.0/CollectionLinks/Campaigns.json"
   },
   {
     "rel": "automations",
     "href": "https://usX.api.mailchimp.com/3.0/automations",
     "method": "GET",
     "targetSchema": "https://api.mailchimp.com/schema/3.0/Automations/Collection.json",
     "schema": "https://api.mailchimp.com/schema/3.0/CollectionLinks/Automations.json"
   },
   {
     "rel": "templates",
     "href": "https://usX.api.mailchimp.com/3.0/templates",
     "method": "GET",
     "targetSchema": "https://api.mailchimp.com/schema/3.0/Templates/Collection.json",
     "schema": "https://api.mailchimp.com/schema/3.0/CollectionLinks/Templates.json"
   },
   {
     "rel": "file-manager",
     "href": "https://usX.api.mailchimp.com/3.0/file-manager",
     "method": "GET",
     "targetSchema": "https://api.mailchimp.com/schema/3.0/FileManager/Namespace.json"
   },
   {
     "rel": "authorized-apps",
     "href": "https://usX.api.mailchimp.com/3.0/authorized-apps",
     "method": "GET",
     "targetSchema": "https://api.mailchimp.com/schema/3.0/AuthorizedApps/Collection.json"
   }
 ]
}

Loading data into Google BigQuery

Google Cloud Platform offers a helpful guide for loading data into BigQuery. You can use the bq command-line tool to upload the files to your awaiting datasets, adding the correct schema and data type information along the way. The bq load command is your friend here. You can find the syntax in the bq command-line tool quickstart guide. Iterate through this process as many times as it takes to load all of your tables into BigQuery.

Keeping Mailchimp data up to date

By now you're definitely thinking that the end is near right? There is still work to be done. After all, what is the point of making a script that moves data to your data warehouse once? What happens tomorrow when you have a thousand new transactions, or heck, just one?

The key is to build your script in such a way that it can also identify incremental updates to your data. Thankfully, MailChimp’s API results include fields like created_at that allow you to quickly identify records that are new since your last update (or since the newest record you’ve copied into Redshift). You can set your script up as a cron job or continuous loop to keep pulling down new data as it appears.

Other data warehouse options

BigQuery is really great, but sometimes you need to optimize for different things when you're choosing a data warehouse. Some folks choose to go with Postgres or Redshift, which are two RDBMSes that use similar SQL syntax. If you're interested in seeing the relevant steps for loading this data into Postgres or Redshift, check out To Redshift and To Postgres.

Easier and faster alternatives

If all this sounds a bit overwhelming, don’t be alarmed. 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 Mailchimp data via the API, structuring it in a way that is optimized for analysis, and inserting that data into your Google BigQuery data warehouse.