Intercom Node.js Client

7.0.3 · active · verified Tue Apr 21

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

Warnings

Install

Imports

Quickstart

Initializes the Intercom client using an environment variable for the API token and demonstrates how to make an API call (e.g., importing AI content) with robust error handling using `IntercomError`.

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();

view raw JSON →