Clients

If you already have an access token you can find it here. If you want to create or learn more about access tokens then you can find more info here.

If you are building a third party application you can get your OAuth token by setting-up-oauth for Intercom.

Users

/** Create a user */$client->users->create(["email"=>"test@example.com","custom_attributes"=> ['foo'=>'bar']]);/** * Update a user (Note: This method is an alias to the create method. In practice you * can use create to update users if you wish)*/$client->users->update(["email"=>"test@example.com","custom_attributes"=> ['foo'=>'bar']]);/** Delete a user by ID */$client->users->deleteUser("570680a8a1bcbca8a90001b9");/** Get a user by ID */$client->users->getUser("570680a8a1bcbca8a90001b9");/** Add companies to a user */$client->users->create(["email"=>"test@example.com","companies"=> [ ["company_id"=>"3" ] ]]);/** Remove companies from a user */$client->users->create(["email"=>"test@example.com","companies"=> [ ["company_id"=>"3","remove"=>true ] ]]);/** Find a single user by email */$client->users->getUsers(["email"=>"bob@example.com"]);/** List all users up to 10k records */$client->users->getUsers([]);/** * List all users (even above 10k records) * The result object contains an array of your user objects and a scroll_param which you can then * use to request the next 100 users. Note that the scroll parameter will time out after one minute * and you will need to make a new request*/$client->users->scrollUsers();

Leads

/** * Create a lead * See more options here: https://developers.intercom.io/reference#create-lead*/$client->leads->create(["email"=>"test@example.com","custom_attributes"=> ['foo'=>'bar']]);/** * Update a lead (Note: This method is an alias to the create method. * In practice you can use create to update leads if you wish)*/$client->leads->update(["email"=>"test@example.com","custom_attributes"=> ['foo'=>'bar']]);/** * List leads * See more options here: https://developers.intercom.io/reference#list-leads*/$client->leads->getLeads([]);/** Find a lead by ID */$client->leads->getLead("570680a8a1bcbca8a90000a9");/** Delete a lead by ID */$client->leads->deleteLead("570680a8a1bcbca8a90000a9");/** Convert a Lead to a User */$client->leads->convertLead(["contact"=> ["user_id"=>"8a88a590-e1c3-41e2-a502-e0649dbf721c" ],"user"=> ["email"=>"winstonsmith@truth.org" ]]);/** * List all leads (even above 10k records) * The result object contains an array of your contacts objects and a scroll_param which you can then * use to request the next 100 leads. Note that the scroll parameter will time out after one minute * and you will need to make a new request*/$client->leads->scrollLeads();

Companies

/** Create a company */$client->companies->create(["name"=>"foocorp", "company_id"=>"3"]);/** * Update a company (Note: This method is an alias to the create method. * In practice you can use create to update companies if you wish)*/$client->companies->update(["name"=>"foocorp", "id"=>"3"]);/** Creating or Update a company with custom attributes. */$client->companies->update(["name"=>"foocorp","id"=>"3","custom_attributes"=> ["foo"=>"bar","baz"=>"qux" ]]);/** List Companies */$client->companies->getCompanies([]);

Admins

/** List admins */$client->admins->getAdmins();

Messages

/** * Send a message from an admin to a user * See more options here: https://developers.intercom.io/reference#conversations*/$client->messages->create(["message_type"=>"inapp","subject"=>"Hey","body"=>"Ponies, cute small horses or something more sinister?","from"=> ["type"=>"admin","id"=>"1234" ],"to"=> ["type"=>"user","email"=>"bob@example.com" ]]);

Conversations

/** * List conversations for an admin * See more options here: https://developers.intercom.io/reference#list-conversations*/$client->conversations->getConversations(["type"=>"admin","admin_id"=>"25610"]);/** Get a single conversation */$client->conversations->getConversation("1234")/** Get a single conversation with plaintext comments */$client->conversations->getConversation("1234", ["display_as"=>"plaintext"])/** * Reply to a conversation * See more options here: https://developers.intercom.io/reference#replying-to-a-conversation*/$client->conversations->replyToConversation("5678", ["email"=>"test@example.com","body"=>"Thanks :)","type"=>"user","message_type"=>"comment"]);/** * Reply to a user's last conversation * See more options here: https://developers.intercom.com/reference#replying-to-users-last-conversation*/$client->conversations->replyToLastConversation(["email"=>"test@example.com","body"=>"Thanks :)","type"=>"user","message_type"=>"comment"]);/** * Mark a conversation as read * See API documentation here: https://developers.intercom.io/reference#marking-a-conversation-as-read*/$client->conversations->markConversationAsRead("7890");

Counts

Notes

/** Create a note */$client->notes->create(["admin_id"=>"21","body"=>"Text for my note","user"=> ["id"=>"5310d8e8598c9a0b24000005" ]]);/** List notes for a user */$client->notes->getNotes(["user_id"=>"25"]);/** Get a single Note by id */$client->notes->getNote("42");

Rate Limits

Rate limit info is passed via the rate limit headers.
You can access this information as follows:

Pagination

When listing, the Intercom API may return a pagination object:

{
"pages": {
"next": "..."
}
}

You can grab the next page of results using the client:

$client->nextPage($response->pages);

Scroll

The first time you use the scroll API you can just send a simple GET request.
This will return up to 100 records. If you have more than 100 you will need to make another call.
To do this you need to use to scroll_parameter returned in the original response.
Use this for subsequent responses until you get an empty array of records.
This means there are no records and the scroll timer will be reset.
For more information on scroll please see the API reference
Here is an example of a simple way to use the scroll for multiple calls:

Exceptions

Exceptions are handled by Guzzle.
The Intercom API may return an unsuccessful HTTP response, for example when a resource is not found (404).
If you want to catch errors you can wrap your API call into a try/catch:

Pull Requests

Document any change in behaviour. Make sure the README and any other
relevant documentation are kept up-to-date.

Create topic branches. Don't ask us to pull from your master branch.

One pull request per feature. If you want to do more than one thing, send
multiple pull requests.

Send coherent history. Make sure each individual commit in your pull
request is meaningful. If you had to make multiple intermediate commits while
developing, please squash them before sending them to us.