How to load data from Intercom to SQL Data Warehouse
This post aims 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 RudderStack that can handle this kind of problem 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 you to write the code to get the data and make sure that this process will run every time new data is generated.
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.
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 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:
- To pull data from it and use it for analytic purposes
- 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:
A typical result will look like this:
Now we can also extract a full list of the conversations that have been performed on Intercom by doing the following:
and a typical result will look like the following:
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
and it supports the following data types:
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:
- 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:
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:
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.
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.