Freshdesk to Redshift

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

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

To use the Freshdesk REST API, your script needs to make HTTP requests, and parse the response. The Freshdesk REST 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. Keep in mind that the rate limit on this API is 1000 calls per hour.

Freshdesk’s API offers access to data endpoints like tickets. Using methods outlined in the API documentation, you can retrieve the data you’d like to move to Redshift.

Sample Freshdesk Data

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

[{
      "cc_email":{
         "cc_emails":[
            "ram@freshdesk.com",
            "diana@freshdesk.com"
            ],
         "fwd_emails":[]
      },
      "created_at":"2014-01-07T14:57:55+05:30",
      "deleted":false,
      "delta":true,
      "description":"Details on the issue ...",
      "description_html":"Details on the issue ...",
      "display_id":138,
      "due_by":"2014-01-10T14:57:55+05:30",
      "email_config_id":null,
      "frDueBy":"2014-01-08T14:57:55+05:30",
      "fr_escalated":false,
      "group_id":null,
      "id":138,
      "isescalated":false,
      "owner_id":null,
      "priority":1,
      "requester_id":17,
      "responder_id":null,
      "source":2,
      "spam":false,
      "status":2,
      "subject":"Support Needed...",
      "ticket_type":"Problem",
      "to_email":null,
      "trained":false,
      "updated_at":"2014-01-07T15:53:21+05:30",
      "urgent":false,
      "status_name":"Open",
      "requester_status_name":"Being Processed",
      "priority_name":"Low",
      "source_name":"Portal",
      "requester_name":"Test",
      "responder_name":"No Agent",
      "product_id":123456,
      "to_emails":null,
      "custom_field":{
         "weapon_1":"Laser Gun"
      }
}]

Preparing Freshdesk 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.

Check out the Stitch Freshdesk 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 Freshdesk 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 Freshdesk and moves it into Redshift.  What happens when Freshdesk 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 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 Freshdesk 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 Freshdesk data via the API, structuring it in a way that is optimized for analysis, and inserting that data into your Redshift data warehouse.