Referral Saasquatch to Redshift

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

First thing you need to do is get your data out of Referral Saasquatch.  That can be done by making calls to Referral Saasquatch’s REST API. The full documentation for the API can be found here.

To use the Referral Saasquatch API, your script will need to make requests using curl, and parse the response which will be in JSON format. Curl syntax is included in the Referral Saasquatch API documentation.

Referral Saasquatch’s API offers access to data endpoints like referrals, reward balance, and users. Using methods outlined in the API documentation, you can retrieve the data you’d like to move to Redshift.

Sample Referral Saasquatch Data

This is an example of what the data looks like from the referrals endpoint.

{
    "count": 2,
    "totalCount": 4,
    "referrals": [
        {
            "id": "5462600de4b09b1c41108f28",
            "referredUser": {
                "id": "898746321",
                "accountId": "987321",
                "email": "hello@example.com",
                "firstName": "Henk",
                "lastName": "Thompson",
                "referralCode": "HENKTHOMPSON",
                "imageUrl": "",
                "firstSeenIP": "10.230.163.157",
                "lastSeenIP": "184.66.242.57",
                "dateCreated": 1467222395030,
                "emailHash": "180bc1412a038746af9b37fb782724a2",
                "referralSource": "http://unifiedtestapp.herokuapp.com/",
                "locale": null,
                "shareLinks": {
                    "shareLink": "http://ssqt.co/mvbcF5",
                    "facebookShareLink": "http://ssqt.co/mmbcF5",
                    "twitterShareLink": "http://ssqt.co/mRbcF5",
                    "emailShareLink": "http://ssqt.co/mLbcF5",
                    "linkedinShareLink": "http://ssqt.co/mLbcF5",
                    "mobileShareLink": "http://ssqt.co/mebcF5",
                    "mobileFacebookShareLink": "http://ssqt.co/mnbcF5",
                    "mobileTwitterShareLink": "http://ssqt.co/mCbcF5",
                    "mobileEmailShareLink": "http://ssqt.co/mEbcF5",
                    "EMBED": {
                        "shareLink": "http://ssqt.co/mQbcF5",
                        "facebookShareLink": "http://ssqt.co/mwbcF5",
                        "twitterShareLink": "http://ssqt.co/mcbcF5",
                        "emailShareLink": "http://ssqt.co/mJbcF5",
                        "linkedinShareLink": "http://ssqt.co/mHbcF5"
                    },
                    "POPUP": {
                        "shareLink": "http://ssqt.co/m5bcF5",
                        "facebookShareLink": "http://ssqt.co/m9bcF5",
                        "twitterShareLink": "http://ssqt.co/mMbcF5",
                        "emailShareLink": "http://ssqt.co/mobcF5",
                        "linkedinShareLink": "http://ssqt.co/m7bcF5"
                    },
                    "HOSTED": {
                        "shareLink": "http://ssqt.co/mtbcF5",
                        "facebookShareLink": "http://ssqt.co/mubcF5",
                        "twitterShareLink": "http://ssqt.co/mSbcF5",
                        "emailShareLink": "http://ssqt.co/mlbcF5",
                        "linkedinShareLink": "http://ssqt.co/mYbcF5"
                    },
                    "MOBILE": {
                        "shareLink": "http://ssqt.co/mebcF5",
                        "facebookShareLink": "http://ssqt.co/mnbcF5",
                        "twitterShareLink": "http://ssqt.co/mCbcF5",
                        "emailShareLink": "http://ssqt.co/mEbcF5",
                        "linkedinShareLink": "http://ssqt.co/m3bcF5"
                    },
                    "EMAIL": {
                        "shareLink": "http://ssqt.co/mPbcF5",
                        "facebookShareLink": "http://ssqt.co/mTbcF5",
                        "twitterShareLink": "http://ssqt.co/mGbcF5",
                        "emailShareLink": "http://ssqt.co/mbbcF5",
                        "linkedinShareLink": "http://ssqt.co/m1bcF5"
                    }
                }
            }
        ]
    }

Preparing Referral Saasquatch Data for Redshift

Now that you have the data you’re looking for, you’ll need to map all those data fields into a schema that can be inserted into your Redshift database. 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 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 Referral Saasquatch 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.  It will work, but isn’t the most efficient way to get the job done.

Redshift offers some helpful 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 an 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 requests data from Referral Saasquatch and moves it into Redshift.  What happens when Referral Saasquatch sends a data type that your script doesn’t recognize?  It’s also important to consider the situation where data in Redshift needs to be updated or replaced. Once you’ve built 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 Referral Saasquatch 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 Referral Saasquatch data via the API, structuring it in a way that is optimized for analysis, and inserting that data into your Redshift data warehouse.