Close.io to Redshift

This page provides you with instructions on how to extract data from Close.io 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 Close.io

For starters, you need to get your data out of Close.io.  That can be done by making calls to the Close.io REST API. The full documentation for the API can be found here.

To use the Close.io REST API, your script needs to make HTTP requests, and parse the response. The API uses JSON as its communication format. The standard HTTP methods like GET, PUT, POST and DELETE are going to be your major tools here.

Close.io’s API offers access to leads, which is the main building block for Close.io data. Using methods outlined in the API documentation, you can retrieve the data you’d like to move to Redshift.

Sample Close.io Data

When you query the Close.io API, it will return JSON formatted data.  Below is an example response from the leads endpoint.

{
    "has_more": false,
    "data": [
        {
            "id": "stat_1ZdiZqcSIkoGVnNOyxiEY58eTGQmFNG3LPlEVQ4V7Nk",
            "label": "Potential"
        },
        {
            "id": "stat_2ZdiZqcSIkoGVnNOyxiEY58eTGQmFNG3LPlEVQ4V7Nk",
            "label": "Bad Fit"
        },
        {
            "id": "stat_3ZdiZqcSIkoGVnNOyxiEY58eTGQmFNG3LPlEVQ4V7Nk",
            "label": "Qualified"
        },
        {
            "id": "stat_8ZdiZqcSIkoGVnNOyxiEY58eTGQmFNG3LPlEVQ4V7Nk",
            "label": "Not Serious"
        }
    ]
}

Preparing Close.io Data for Redshift

Now that you’ve got JSON, you 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 Close.io 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 Close.io 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 first reaction.  That is a good idea, but it isn’t the most efficient way to get from A to B.

Redshift offers a sweet piece of documentation for how to best bulk insert data into new tables. The COPY command is particularly useful in situations like this, 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 an INSERT statement, and then use EXECUTE as many times as required. This helps avoid some of the overhead of repeatedly parsing and planning INSERT.

Keeping Data Up-To-Date

Ok, you’ve built a script that requests data from Close.io and moves it into Redshift.  What happens next week when you need to access the most recent leads?  It’s also important to consider the situation where an entry in Redshift needs to be updated to a new value. Build in that functionality and 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 pretty great, but perhaps you need to start smaller or optimize for different things. In a situation like that, lots of 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 Close.io to Postgres

Easier and Faster Alternatives

If you have all the skills necessary to go through this process, you  might have other projects that you need to be focusing on.

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