How to load data from Intercom to SQL Data Warehouse

Blendo Team

So, you decided you want to analyse the data you have on Intercom and do that on SQL Data Warehouse. The purpose of this post is to help you define a process or pipeline, to load data from Intercom to SQL Data Warehouse for further analysis. Alternatively you can use products like Blendo that can handle this kind of problems automatically for you.

Information will be given on how to access and extract your data from Intercom through its API and how to load it into SQL Data Warehouse, this process requires from you to write the code to get the data and make sure that this process will run every time new data are generated.

“]

About Microsoft Azure SQL Data Warehouse

SQL Data Warehouse is the data warehousing solution that you can use if you are a user of Microsoft Azure. It’s an elastic data warehousing as a service solution, emphasizing it’s enterprise focus. It also speaks SQL like the previous two solutions and it supports querying both relational and non-relational data.  It offers a number of enterprise-class features like support for hybrid cloud installations and strong security. It’s probably the less mature solution compared to the two others though, it’s still in “Preview” mode although accessible to existing Azure subscribers.

About Intercom

Intercom is a fundamentally new way to communicate with your customers. It is one place for every team in an internet business to communicate with customers, personally, at scale – on your website, inside web and and mobile apps, and by email. It offers four products.

  • Acquire – which helps you to communicate with your customers by chatting with them
  • Engage – which helps you to onboard and retain your customers with targeted emails and in-app messages
  • Learn – which helps you to get feedback from your customers more effectively
  • Support – which helps you to support your customers from inside your application

Extract your data from Intercom

Intercom exposes a rich REST API for interacting with its services. There are two reasons someone would like to use the Intercom REST API:

  1. To pull data from it and use it for analytic purposes
  2. To push data into to to enrich the information it contains for customers and enhance its service

At this post we’ll focus mainly on pulling data from the API and use it to enrich our data warehouse with data that are generated from our interactions with our customers.

The main entities of the Intercom API are the following:

  • Users – which is the primary way of interacting with Intercom.
  • Leads – represent logged-out users of your application.
  • Companies – allow you to represent commercial organizations using your product.
  • Tags – A tag allows you to label your users and companies and list them using that tag.
  • Segments – A segment is a group of your users defined by rules that you set.
  • Notes – Notes allow you to annotate and comment on your users.
  • Events – Events are how you can submit user activity to Intercom.
  • Counts – You can get counts of users and companies filtered by certain criteria.
  • Conversations – Conversation are how you can communicate with users in Intercom.

At this point it has to be noted that not all of the above entities can be pulled out from the Intercom API. For example, Events can only be pushed inside Intercom and it’s not possible to extract them again. So if you plan to use Intercom also for tracking the behaviour of your users keep that in mind, because contrary to services like Mixpanel, it’s not possible to pull the user events from the system. A good strategy for ensuring that your user activity will be pushed on all the different services that you need and that you will always have access to the data is by using a service like Segment.

Intercom Exposes a RESTful web API, which means that we interact with its resources through http verbs like POST and GET by using an http client. Intercom also offers a number of SDKs that are build around an http client for a number of popular languages:

Pull data from the Intercom REST API

A typical use case for pulling data out of Intercom is to fetch all your users together with all the conversations you have done with each one. Then you can load this information to your data warehouse and enhance your analytic capabilities with additional interactions that you had with them. To do that you first need to get all your users, with CURL you can do that in the following way:

curl https://api.intercom.io/users -u pi3243fa:da39a3ee5e6b4b0d3255bfef95601890afd80709 -H 'Accept: application/json'

A typical result will look like this:

{ "type": "user.list", "total_count": 105, "users": [ { "type": "user", "id": "530370b477ad7120001d", ... }, ... ],   "pages": { "next": "https://api.intercom.io/users?per_page=50&page=2", "page": 1, "per_page": 50, "total_pages": 3 } }

Now we can also extract a full list of the conversations that have been performed on Intercom by doing the following:

$ curl https://api.intercom.io/conversations?type=admin&admin_id=25&open=true -u pi3243fa:da39a3ee5e6b4b0d3255bfef95601890afd80709 -H 'Accept:application/json'

and a typical result will look like the following:

{ "type": "conversation.list", "conversations": [ { "type": "conversation", "id": "147", "created_at": 1400850973, "updated_at": 1400857494, "user": { "type": "user", "id": "536e564f316c83104c000020" }, "assignee": { "type": "admin", "id": "25" }, "conversation_message": { "type": "conversation_message", "subject": "", "body": "<p>Hi Alice,</p>nn<p>We noticed you using our Product, do you have any questions?</p> n<p>- Jane</p>", "author": { "type": "admin", "id": "25" }, "attachments": [ { "name": "signature", "url": "http://someurl.com/signature.jpg" } ] } } ] }

As we can see, each conversation contains a user object which contains an id, in this way we can associate the conversations with the users we had extracted earlier. Of course in order to do that on our Data warehouse repository we need to map the above structures to the data model that the repository follows by respecting both the schema and the data types. Then we can write a pipeline that will extract the data and transform it into the model of our repository and load the data by following the instructions that follow below. Of course if something changes on the Intercom API the pipeline will break and we will have to take care of it.

Use webhooks to push events from Intercom to your data warehouse

Intercom also supports the definition of webhooks, where you can register certain events and the system will push there a message whenever the events is triggered. So for example you might define a webhook that will push a message every time a new conversation is performed with your customers. By doing this it is possible to create a near real time streaming load process on for your data warehouse. In order to implement something like that though, you need to take into consideration the limitations of both ends, while ensuring that delivery semantics that your use case requires for the data management infrastructure that you will build.

For more information you can check the webhooks section on the Intercom API documentation.

Prepare your Intercom Data for SQL Data Warehouse

SQL Data Warehouse shares many common characteristics with SQL Server. It’s also a relational database that requires a Schema but it doesn’t support the following SQL Server features:

  • Primary keys
  • Foreign keys
  • Check constraints
  • Unique constraints
  • Unique indexes
  • Computed columns
  • Sparse columns
  • User defined types
  • Indexed views
  • Identities
  • Sequences
  • Triggers
  • Synonyms

and it supports the following data types:

  • bigint
  • binary
  • bit
  • char
  • date
  • datetime
  • datetime2
  • datetimeoffset
  • decimal
  • float
  • int
  • money
  • nchar
  • nvarchar
  • real
  • smalldatetime
  • smallint
  • smallmoney
  • time
  • tinyint
  • varbinary
  • varchar

As your data are probably coming in a representation like JSON that supports a much smaller range of data types you have to be really careful about what data you feed into SQL Data Warehouse and make sure that you have mapped your types into one of the datatypes that is supported by it. Designing a Schema for SQL Data Warehouse and mapping the data from your data source to it is a process that you should take seriously as it can both affect the performance of your cluster and the questions that you can answer. It’s always a good idea to have in your mind the documentation that Microsoft Azure has published regarding the design of an SQL Data Warehouse database.

Load Data from Intercom to SQL Data Warehouse

SQL Data Warehouse support numerous options for loading data, such us:

  • PolyBase
  • Azure Data Factory
  • BCP command-line utility
  • SQL Server integration services

As we are interested in loading data from online services by using their exposed HTTP APIs, we are not going to consider the usage of BCP command-line utility or SQL server integration in this guide. We’ll consider the case of loading our data as Azure storage Blobs and then use PolyBase to load the data into SQL Data Warehouse.

Accessing these services happens through HTTP APIs, as we see again APIs play an important role in both the extraction but also the loading of data into our data warehouse. You can access these APIs by using a tool like CURL or Postman. Or use the libraries provided by Microsoft for your favourite language. Before you actually upload any data you have to create a container which is something similar as a concept to the Amazon AWS Bucket, creating a container is a straight forward operation and you can do it by following the instructions found on the Blog storage documentation from Microsoft. As an example, the following code can create a container in Node.js.

blobSvc.createContainerIfNotExists('mycontainer', function(error, result, response){ if(!error){ // Container exists and allows // anonymous read access to blob // content and metadata within this container } });

After the creation of the container you can start uploading data to it by using again the given SDK of your choice in a similar fashion:

blobSvc.createBlockBlobFromLocalFile('mycontainer', 'myblob', 'test.txt', function(error, result, response){ if(!error){ // file uploaded } });

When you are done putting your data into Azure Blobs you are ready to load it into SQL Data Warehouse using PolyBase. To do that you should follow the directions in the Load with PolyBase documentation. In a summary the required steps to do it, are the following:

  • create a database master key
  • create a database scoped credentials
  • create an external file format
  • create an external data source

PolyBase’s ability to transparently parallelize loads from Azure Blob Storage will make it the fastest tool for loading data. After configuring PolyBase, you can load data directly into your SQL Data Warehouse by simply creating an external table that points to your data in storage and then mapping that data to a new table within SQL Data Warehouse.

Of course you will need to establish a recurrent process that will extract any newly created data from your service, load them in the form of Azure Blobs and initiate the PolyBase process for importing the data again into SQL Data Warehouse. One way of doing this is by using the Azure Data Factory service. In case you would like to follow this path you can read some good documentation on how to move data to and from Azure SQL Warehouse using Azure Data Factory.

The best way to load data from Intercom to SQL Data Warehouse and possible alternatives

So far we just scraped the surface of what can be done with Microsoft Azure SQL Data Warehouse and how to load data into it. The way to proceed relies heavily on the data you want to load, from which service they are coming from and the requirements of your use case. Things can get even more complicated if you want to integrate data coming from different sources. A possible alternative, instead of writing, hosting and maintaining a flexible data infrastructure, is to use a product like Blendo that can handle this kind of problems automatically for you.

Blendo integrates with multiple sources or services like databases, CRM, email campaigns, analytics and more. Quickly and safely move all your data from Intercom into SQL Data Warehouse and start generating insights from your data.