Using the Intercom API to Get Companies (with PHP examples)

by Endgrate Team 2024-07-10 5 min read

Intercom homepage

Introduction to Intercom API Integration

Intercom is a powerful customer communication platform that enables businesses to engage with their customers through personalized messaging and support. It offers a suite of tools for managing customer interactions, including live chat, email marketing, and customer feedback.

Integrating with Intercom's API allows developers to access and manage company data efficiently. For example, you can retrieve a list of companies associated with your Intercom account to analyze customer segments or tailor marketing strategies. This integration can streamline workflows and enhance customer relationship management.

Setting Up Your Intercom Developer Account for API Integration

Before you can start using the Intercom API to retrieve company data, you'll need to set up a developer account and create an app. This will allow you to authenticate your requests and access the necessary data.

Create a Free Intercom Developer Account

If you don't already have an Intercom account, you can sign up for a free developer account. This will give you access to the Developer Hub, where you can manage your apps and configure OAuth settings.

  • Visit the Intercom Developer Hub and sign up for a free account.
  • Once registered, log in to access your Developer Hub.

Set Up a Development Workspace

To build and test your integration, you'll need a development workspace. This environment allows you to configure and test your app without affecting live data.

  • Navigate to the "Workspaces" section in the Developer Hub.
  • Create a new development workspace by following the on-screen instructions.

Configure OAuth for Your Intercom App

Intercom uses OAuth for authentication, allowing secure access to user data. Follow these steps to set up OAuth for your app:

  • In the Developer Hub, go to the "Apps" section and create a new app.
  • Enable OAuth by selecting the "Use OAuth" option on the Authentication page.
  • Provide the necessary redirect URLs, ensuring they use HTTPS.
  • Select the permissions your app requires, such as reading and listing companies.

For detailed instructions, refer to the Intercom OAuth setup guide.

Generate Your Client ID and Client Secret

After configuring OAuth, you'll receive a client ID and client secret. These credentials are essential for authenticating your API requests.

  • Find your client ID and client secret on the "Basic Information" page of your app in the Developer Hub.
  • Store these credentials securely, as they will be used in your API calls.

With your Intercom developer account and app set up, you're ready to start making API calls to retrieve company data. In the next section, we'll explore how to use PHP to interact with the Intercom API.

Intercom authentication documentation page.
sbb-itb-96038d7

How to Make API Calls to Retrieve Companies Using Intercom API with PHP

In this section, we'll guide you through making API calls to the Intercom API using PHP to retrieve company data. This will involve setting up your PHP environment, installing necessary dependencies, and executing the API call.

Setting Up Your PHP Environment for Intercom API Integration

Before making API calls, ensure your PHP environment is properly configured. You'll need PHP 7.4 or later and the Composer package manager to handle dependencies.

Installing GuzzleHTTP for HTTP Requests in PHP

We'll use GuzzleHTTP, a PHP HTTP client, to make requests to the Intercom API. Install it using Composer:

composer require guzzlehttp/guzzle

Making an API Call to Retrieve Companies from Intercom

With your environment set up, you can now make an API call to retrieve companies. Here's a step-by-step guide:


<?php
require 'vendor/autoload.php';

use GuzzleHttp\Client;

// Initialize the Guzzle client
$client = new Client();

// Set the API endpoint and headers
$endpoint = 'https://api.intercom.io/companies';
$headers = [
    'Authorization' => 'Bearer YOUR_ACCESS_TOKEN',
    'Intercom-Version' => '2.11',
    'Accept' => 'application/json'
];

// Make the GET request to the Intercom API
$response = $client->request('GET', $endpoint, ['headers' => $headers]);

// Parse the JSON response
$data = json_decode($response->getBody(), true);

// Output the company data
foreach ($data['data'] as $company) {
    echo 'Company Name: ' . $company['name'] . "\n";
    echo 'Company ID: ' . $company['id'] . "\n";
    echo 'Industry: ' . $company['industry'] . "\n\n";
}
?>

Replace YOUR_ACCESS_TOKEN with the access token you obtained during the OAuth setup. This script initializes a Guzzle client, sets the necessary headers, and makes a GET request to the Intercom API to retrieve company data.

Verifying Successful API Requests and Handling Errors

After running the script, you should see a list of companies printed to your console. If the request fails, handle errors gracefully by checking the response status code:


if ($response->getStatusCode() !== 200) {
    echo 'Error: ' . $response->getReasonPhrase();
    exit;
}

For more information on error codes, refer to the Intercom API documentation.

Intercom API call documentation page.

Conclusion and Best Practices for Intercom API Integration with PHP

Integrating with the Intercom API using PHP provides a powerful way to manage and analyze company data, enhancing your customer relationship management strategies. By following the steps outlined in this guide, you can efficiently retrieve and utilize company information from your Intercom account.

Best Practices for Secure and Efficient Intercom API Usage

  • Secure Storage of Credentials: Always store your client ID, client secret, and access tokens securely. Consider using environment variables or a secure vault to manage sensitive information.
  • Handle Rate Limiting: Be mindful of Intercom's rate limits to avoid throttling. Implement exponential backoff strategies to handle rate limit errors gracefully. For more details, refer to the Intercom API documentation.
  • Data Standardization: Ensure that data retrieved from Intercom is standardized and transformed as needed to fit your application's requirements.
  • Error Handling: Implement robust error handling to manage API call failures. Log errors for troubleshooting and provide user-friendly messages when issues occur.

Streamlining Integration Processes with Endgrate

While integrating with the Intercom API can significantly enhance your application's capabilities, managing multiple integrations can be complex and time-consuming. Endgrate simplifies this process by offering a unified API endpoint for various platforms, including Intercom.

By leveraging Endgrate, you can save time and resources, allowing your team to focus on core product development. Build once for each use case and enjoy an intuitive integration experience for your customers. Explore more about how Endgrate can streamline your integration efforts by visiting Endgrate's website.

Read More

Ready to get started?

Book a demo now

Book Demo