Intercom Node.js Client
The `intercom-client` package provides the official Node.js and TypeScript bindings for interacting with the Intercom API. It is currently stable at version `7.0.3` and supports Intercom API v2.14 as of its v7.0.0 release. The library maintains a frequent release cadence, often driven by automatic code generation via Fern, ensuring it stays up-to-date with the latest Intercom API specifications. Key features include comprehensive TypeScript type definitions for request and response payloads, built-in support for paginated list endpoints through iterators, automatic request retries with exponential backoff for transient errors, and configurable request timeouts. It is designed for modern Node.js environments, requiring Node.js 18 or newer, and embraces ESM imports.
Common errors
-
Error: INTERCOM_ACCESS_TOKEN environment variable is not set.
cause The Intercom client was initialized without an API token, or the environment variable was missing.fixSet the `INTERCOM_ACCESS_TOKEN` environment variable with your actual Intercom API token or pass `{ token: 'YOUR_TOKEN' }` directly to the `IntercomClient` constructor. For production, environment variables are recommended. -
Intercom API Error [401]: Unauthorized
cause The provided Intercom API token is invalid, expired, or lacks the necessary permissions for the requested action.fixVerify that your `INTERCOM_ACCESS_TOKEN` is correct and active in your Intercom workspace. Check if the token has the required scopes/permissions for the API endpoint you are calling. -
Intercom API Error [404]: Not Found
cause The requested resource (e.g., user, conversation, article by ID) does not exist, or the endpoint path is incorrect.fixDouble-check the IDs or parameters used in your API call. Review the Intercom API documentation to confirm the correct endpoint path and resource existence. -
Intercom API Error [429]: Too Many Requests
cause You have exceeded Intercom's API rate limits for your workspace.fixThe library has built-in retries, but for sustained high load, implement client-side rate limiting or back-off strategies in your application. Review Intercom's rate limit documentation.
Warnings
- breaking Version `7.0.0` of `intercom-client` introduced support for Intercom API v2.14. This major version bump likely includes breaking changes to the API surface, endpoint paths, or data structures. Users migrating from `v6.x` or earlier should consult the official Intercom API documentation and the client's reference for specific changes relevant to their utilized endpoints.
- gotcha The library explicitly targets modern Node.js environments (`>=18.0.0`) and is written in TypeScript, preferring ES Module (ESM) import syntax. While CommonJS `require()` might partially function, using `import` statements is the recommended and best-supported approach, especially for type safety and future compatibility.
- gotcha API errors (non-2xx HTTP responses) are encapsulated within `IntercomError` instances. Direct checks of `response.status` might not be necessary if you catch `IntercomError` to access `statusCode`, `message`, `body`, and `rawResponse` for comprehensive error handling.
- gotcha Pagination for list endpoints has specific patterns, either using `for await...of` iterators or manual `hasNextPage()` and `getNextPage()` methods on the returned `PageableResponse` object. Attempting to directly destructure a paginated response like a simple array will not work for fetching subsequent pages.
Install
-
npm install intercom-client -
yarn add intercom-client -
pnpm add intercom-client
Imports
- IntercomClient
const IntercomClient = require('intercom-client').IntercomClient;import { IntercomClient } from 'intercom-client'; - Intercom
import * as Intercom from 'intercom-client';
import { Intercom } from 'intercom-client'; - IntercomError
import { Error } from 'intercom-client';import { IntercomError } from 'intercom-client';
Quickstart
import { IntercomClient, IntercomError } from "intercom-client";
// Initialize the Intercom client with an API token from environment variables.
// It's crucial to protect your Intercom API token and avoid hardcoding it.
const INTERCOM_ACCESS_TOKEN = process.env.INTERCOM_ACCESS_TOKEN ?? '';
if (!INTERCOM_ACCESS_TOKEN) {
console.error("Error: INTERCOM_ACCESS_TOKEN environment variable is not set.");
process.exit(1);
}
const client = new IntercomClient({ token: INTERCOM_ACCESS_TOKEN });
async function importContent() {
try {
// Example: Create a content import source for AI capabilities.
// Replace with the actual endpoint and parameters you intend to use.
const result = await client.aiContent.createContentImportSource({
url: "https://www.example.com/your-business-faq-page",
// Additional parameters might be required depending on the specific API call.
// Refer to the Intercom API documentation for required fields.
});
console.log("Content import initiated successfully:", result);
} catch (err) {
if (err instanceof IntercomError) {
console.error(`Intercom API Error [${err.statusCode}]: ${err.message}`);
console.error("Error Body:", err.body);
console.error("Raw Response:", err.rawResponse);
} else {
console.error("An unexpected error occurred:", err);
}
}
}
importContent();