Table of Contents

Create Contacts in Intercom

Abby Updated by Abby

With the Intercom API we can create contacts in Intercom directly from the flow of our bot

Later we'll be able to create tickets associated with these contacts and optionally assign them to certain inboxes

Here's what the flow will look like:

STEP 1: Get Intercom API key

Before getting started we'll need our API key from Intercom, in order to get this you'll first need to create an 'app', this will generate an API key (in the authentication tab) that we can use for all Intercom requests from Landbot

STEP 2(Optional): Check if contact exists

Before adding a new contact we should check if the contact already exists, in order to avoid duplication of our contacts in Intercom, this is optional but recommended

We'll first ask for their name and email, then we'll search Intercom to see if they already exist

Here's what we need to add in the webhook:

A POST to this endpoint: https://api.intercom.io/contacts/search

We'll add the Authorization in the Header as Authorization Bearer XXXXXXXXX

Then as another field in the Header we'll add Content-Type application/json

Here's what we'll add in the BODY:

{

"query": {

"field": "email",

"operator": "~",

"value": "@email"

}

}

Next we want to test the request with an email that exists in our contacts

We should get this response:

What we want to save here is the Intercom ID and the count, or rather the number of contacts that exist with this specific email, we can find this by scrolling to the bottom of the response in the purple drop down

Step 3: Condition

After we save the total number of contacts with the email we can use a condition to check if it's more than 0

This will let us know whether this contact exists or not as a contact in Intercom

If they already exist, they will go through the green flow, where we can later create a ticket in Intercom

However, if they don't exist now we can use another webhook to create the contact

Step 4: Create contact

We'll do a POST to this url: https://api.intercom.io/contacts

With the same Headers as last time

Here's what we'll put in our BODY

{
"role": "lead",
"external_id": "@id",
"email": "@email",
"name": "@name",
"unsubscribed_from_emails": true
}

We want to test the request with real values and then save the Intercom ID to use later on

Now that we have contacts and their ID we can create tickets and assign them (coming soon)!

How did we do?

Create a Ticket in Intercom

Contact