Using the Intercom API to Get Notes (with Python examples)

by Endgrate Team 2024-07-19 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 messaging, email, and more. It offers a suite of tools designed to enhance customer support, marketing, and sales efforts, making it a popular choice for businesses aiming to improve customer relationships.

Developers may want to integrate with Intercom's API to access and manage customer interactions, such as notes, which can be used to annotate and comment on customer profiles. For example, a developer might use the Intercom API to retrieve notes associated with a contact, allowing for better tracking of customer interactions and insights into customer needs.

This article will guide you through using Python to interact with the Intercom API, specifically focusing on retrieving notes. By the end of this tutorial, you'll be able to efficiently access and manage notes on the Intercom platform using Python.

Setting Up Your Intercom Test Account for API Integration

Before diving into the Intercom API, you'll need to set up a test account to experiment with API calls without affecting live data. Intercom provides a development workspace that allows you to build and test integrations safely.

Creating a Development Workspace in Intercom

To begin, you'll need to create a development workspace. This workspace is essential for testing your integration and accessing the Intercom Developer Hub.

  1. Visit the Intercom Developer Hub and sign up for a free account.
  2. Once registered, navigate to the Developer Hub and select "Create a new app."
  3. Choose the option to set up a development workspace. This will give you access to the necessary tools and resources for building your integration.

Configuring OAuth for Intercom API Access

Intercom uses OAuth for authentication, which allows your app to access user data securely. Follow these steps to configure OAuth:

  1. In your development workspace, go to the "Authentication" section and enable the "Use OAuth" option.
  2. Provide the necessary redirect URLs. These URLs are where Intercom will send the authorization code after a user authorizes your app. Ensure these URLs use HTTPS.
  3. Select the required permissions for your app. For accessing notes, ensure you have the appropriate scopes selected, such as "Read and write users."
  4. Save your changes and note down your client_id and client_secret, which you'll need for the OAuth flow.

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

Generating an Access Token

With OAuth configured, you can now generate an access token to authenticate API requests:

  1. Redirect users to the following URL to obtain an authorization code:
  2. https://app.intercom.com/oauth?client_id=YOUR_CLIENT_ID&state=YOUR_STATE
  3. Once the user authorizes your app, they will be redirected to your specified URL with a code parameter.
  4. Exchange this code for an access token by making a POST request to:
  5. https://api.intercom.io/auth/eagle/token
  6. Include the following parameters in the request body: code, client_id, and client_secret.

Upon successful exchange, you'll receive an access token, which you can use to authenticate your API requests. For more details, check the Intercom API documentation.

Intercom authentication documentation page.
sbb-itb-96038d7

Making API Calls to Retrieve Notes from Intercom Using Python

To interact with the Intercom API and retrieve notes, you'll need to set up your Python environment and make HTTP requests to the appropriate endpoints. This section will guide you through the process of making API calls using Python to access notes associated with a contact in Intercom.

Setting Up Your Python Environment for Intercom API Integration

Before making API calls, ensure you have Python installed on your machine. This tutorial uses Python 3.11.1. Additionally, you'll need the requests library to handle HTTP requests. Install it using the following command:

pip install requests

Retrieving Notes from Intercom API with Python

Once your environment is set up, you can proceed to retrieve notes using the Intercom API. Follow these steps to make the API call:

  1. Create a new Python file named get_intercom_notes.py and add the following code:
import requests

# Replace with your contact ID and access token
contact_id = "YOUR_CONTACT_ID"
access_token = "YOUR_ACCESS_TOKEN"

# Set the API endpoint and headers
url = f"https://api.intercom.io/contacts/{contact_id}/notes"
headers = {
    "Authorization": f"Bearer {access_token}",
    "Intercom-Version": "2.11"
}

# Make a GET request to the API
response = requests.get(url, headers=headers)

# Check if the request was successful
if response.status_code == 200:
    notes = response.json()
    print("Notes retrieved successfully:")
    for note in notes['data']:
        print(note['body'])
else:
    print(f"Failed to retrieve notes. Status code: {response.status_code}")

Replace YOUR_CONTACT_ID and YOUR_ACCESS_TOKEN with your actual contact ID and access token obtained from the OAuth process.

Running the Python Script and Verifying API Call Success

Run the script using the following command:

python get_intercom_notes.py

If the request is successful, you should see the notes associated with the specified contact printed in the console. If the request fails, the script will output the status code, which can help diagnose the issue.

Handling Errors and Understanding Intercom API Response Codes

When making API calls, it's essential to handle potential errors gracefully. The Intercom API may return various status codes, such as:

  • 200 OK: The request was successful, and the notes were retrieved.
  • 401 Unauthorized: The access token is invalid or expired. Ensure your token is correct and hasn't expired.
  • 404 Not Found: The specified contact ID does not exist. Verify the contact ID is correct.

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

Intercom API call documentation page.

Conclusion and Best Practices for Using Intercom API with Python

Integrating with the Intercom API to retrieve notes can significantly enhance your ability to manage customer interactions and gain insights into customer needs. By following the steps outlined in this article, you can efficiently set up OAuth authentication, make API calls, and handle responses using Python.

Best Practices for Secure and Efficient Intercom API Integration

  • Securely Store Credentials: Always store your client ID, client secret, and access tokens securely. Consider using environment variables or a secure vault to protect sensitive information.
  • Handle Rate Limiting: Be aware of Intercom's rate limits to avoid exceeding them. Implement retry logic with exponential backoff to handle rate limit errors gracefully.
  • Data Standardization: Ensure that the data retrieved from Intercom is standardized and transformed as needed to fit your application's requirements.
  • Error Handling: Implement robust error handling to manage different response codes and potential issues with API requests.

Enhance Your Integration Strategy with Endgrate

While integrating with the Intercom API can be a powerful way to enhance your customer communication strategy, managing multiple integrations can be complex and time-consuming. Endgrate offers a streamlined solution by providing a unified API endpoint that connects to various platforms, including Intercom.

By leveraging Endgrate, you can save time and resources, allowing your team to focus on core product development while ensuring a seamless integration experience for your customers. Visit Endgrate to learn more about how you can simplify your integration processes.

Read More

Ready to get started?

Book a demo now

Book Demo