Feeling stuck with Segment? Say 👋 to RudderStack.

SVG
Log in

How to load data from Intercom to SQL Data Warehouse

About Microsoft Azure SQL Data Warehouse

SQL Data Warehouse is the data warehousing solution you can use if you are a user of Microsoft Azure. It’s an elastic data warehouse as a service solution, emphasizing its 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 still in Preview mode, although accessible to existing Azure subscribers.

[@portabletext/react] Unknown block type "aboutNodeBlock", specify a component for it in the `components.types` prop

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 enrich the information, it contains for customers and enhance its service

In this post, we’ll focus mainly on pulling data from the API and using it to enrich our data warehouse with data 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 – Conversations 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 to track your users’ behavior, 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 you need and that you will always have access to the data is 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 built 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. You can then load this information to your data warehouse and enhance your analytic capabilities with additional interactions with them. To do that you first need to get all your users, with CURL you can do that in the following way:

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

A typical result will look like this:

JSON
{ "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:

SH
$ 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:

JSON
{ "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. 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. 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 are triggered. 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 for your data warehouse. To implement something like that, though, you need to consider the limitations of both ends while ensuring the 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 is probably coming in a representation similar to JSON (supports smaller range of data types) you have to be 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 are supported by it.

Designing a Schema for SQL Data Warehouse and mapping the data from your data source 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 as:

  • 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 will not 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. APIs play an important role in both the extraction and 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 favorite language. Before you actually upload any data you have to create a container which is something similar to a concept to the Amazon AWS Bucket, creating a container is a straightforward 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:

JAVASCRIPT
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:

JAVASCRIPT
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 loading data tool. 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 it to a new table within SQL Data Warehouse.

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 your use case’s requirements. Things can get even more complicated if you want to integrate data coming from different sources. Instead of writing, hosting, and maintaining a flexible data infrastructure, a possible alternative is to use a product like RudderStack to handle this kind of problem for you automatically.

RudderStack 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 generate insights from your data. Don't want to go through the pain of direct integration? RudderStack’s Intercom to SQL Data Warehouse makes it easy to send data from Intercom to SQL Data Warehouse.

Sign Up For Free And Start Sending Data

Test out our event stream, ELT, and reverse-ETL pipelines. Use our HTTP source to send data in less than 5 minutes, or install one of our 12 SDKs in your website or app.