All Collections
Import Scripts
Import data from Intercom
Import data from Intercom

Example Javascript code for importing leads or users from Intercom

Ben McRedmond avatar
Written by Ben McRedmond
Updated over a week ago

You can use Import Scripts to import lead or user data from your Intercom account directly into an Equals workbook.

1. Create an Intercom Access Token

Follow the instructions here to create an Intercom access token.

2. Add the key to a secret group

Copy the access token from the prior step. Then create a new secret group and paste the key into a new secret named intercom_api_key.

3. The code

Once you've completed the prior steps, create a new workbook, add a new import script to a sheet and copy + paste the script below. Once pasted select your secret group in the toolbar (make sure the key in the secret group is called intercom_api_key). If you'd like to fetch users instead of leads, change role to user.

const equals = require("equals");
const axios = require("axios");
const luxon = require("luxon");

const apiKey = equals.getSecret("intercom_api_key");
const role = "lead";

const unixToDateTime = (unixTimestamp) =>
luxon.DateTime.fromSeconds(unixTimestamp).toFormat('yyyy-LL-dd HH:mm:ss');

const getLeadsPage = async (starting_after = undefined) => {
const response = await axios({
method: "post",
url: "",
data: {
query: {
field: "role",
operator: "=",
value: role
pagination: { per_page: 150, starting_after },
sort: { field: "created_at", order: "descending" },
headers: {
Authorization: `Bearer ${apiKey}`,
Accept: "application/json"

const getAllLeads = async () => {
let leads = [];
let response;
let startingAfter;
do {
response = await getLeadsPage(startingAfter);
leads = leads.concat(;
startingAfter = &&;
} while(startingAfter);
return leads;

const leads = await getAllLeads();

equals.addHeaders(["email", "created_at"])
leads.forEach((lead) => {
lead["created_at"] = unixToDateTime(lead["created_at"]);
Did this answer your question?