Quickbooks to Redshift

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

Pulling Data Out Of Quickbooks

The first step of getting your Quickbooks data into AWS Redshift is pulling that data off of Quickbooks’ servers. You can do this using the Quickbooks Accounting and Payments API’s which are available to everyone who uses the service. The full programming guide can be accessed here.

Sample Quickbooks Data

The API returns XML-formatted data. Below is an example of the kind of response you might see when querying the api.

<div class="codeDiv">
<pre>
<code><p><IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2013-04-03T10:22:55.766Z">
 <QueryResponse startPosition="10" maxResults="2">
 <Customer>
 <Id>2123</Id>
 <SyncToken>0</SyncToken>
 ...
 <GivenName>Srini</GivenName>
 </Customer>
 <Customer>
 <Id>2124</Id>
 <SyncToken>0</SyncToken>
 ...
 <GivenName>Peter</GivenName>
 </Customer>
 </QueryResponse>
</IntuitResponse>
</p></code>
</pre>
</div>

Preparing Quickbooks Data for Redshift

With the XML 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.

Check out the Stitch Quickbooks Documentation to get a good sense of what fields and data types will be provided by each endpoint. Once you have identified all of the columns you will want to insert, use the CREATE TABLE statement in Redshift to build a table that will receive all of this data.

Inserting Quickbooks 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.  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, now what? You’ve built a script that pulls data from Quickbooks and loads it into Redshift, but what happens tomorrow when you have new transactions?

The key is to build your script in such a way that it can also identify incremental updates to your data. Some API’s include fields like ‘time’ 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

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 Quickbooks 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 Quickbooks data via the API, structuring it in a way that is optimized for analysis, and inserting that data into your Amazon Redshift data warehouse.