Intercom PHP SDK

Intercom PHP SDK Examples

πŸ“˜

Installation and Configuration Steps

For information on how to install and configure the Intercom PHP SDK please see the intercom-php github page. For general code examples please see below.

Clients

use Intercom\IntercomClient; 
 $client = new IntercomClient(<insert_token_here>, null);

Users

$client->users->create(["email" => "[email protected]"]);
$client->users->deleteUser("570680a8a1bcbca8a90001b9");
// Add companies to a user
$client->users->create(["email" => "[email protected]",
  "companies" => [
    [
      "id" => "3"
    ]
  ]
]);
$client->users->getUsers(["email" => "[email protected]"]);
$client->users->getUsers([]);

Leads

// See more options here: https://developers.intercom.io/reference#create-lead
$client->leads->create([]);
$client->leads->deleteLead("570680a8a1bcbca8a90000a9");
$leads->convertLead([
  "contact" => [
    "user_id" => "8a88a590-e1c3-41e2-a502-e0649dbf721c"
  ],
  "user" => [
    "email" => "[email protected]"
  ]
]);
$client->leads->getLead("570680a8a1bcbca8a90000a9");
// See more options here: https://developers.intercom.io/reference#list-leads
$client->leads->getLeads([]);

Tags

$client->tags->tag([
  "name" => "Test",
  "users" => [
    ["id" => "1234"]
  ]
]);
$client->tags->getTags();

Events

$client->events->create([
  "event_name" => "testing",
  "created_at" => 1391691571,
  "email" => "[email protected]"
]);
$client->events->getEvents(["email" => "[email protected]"]);

Companies

$client->companies->create([
  "name" => "foocorp", "id" => "3"
]);
$client->companies->getCompanies([]);

Admins

$client->admins->getAdmins();

Messages

// 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" => "[email protected]"
  ]
]);

Conversations

// See more options here: https://developers.intercom.io/reference#list-conversations
$client->conversations->getConversations([
  "type" => "admin",
  "admin_id" => "25610"
]);
$client->conversations->getConversation("1234")
// See more options here: https://developers.intercom.io/reference#replying-to-a-conversation
$client->conversations->replyToConversation("5678", [
  "email" => "[email protected]",
  "body" => "Thanks :)",
  "type" => "user",
  "message_type" => "comment"
]);

Counts

// See more options here: https://developers.intercom.io/reference#getting-counts
$client->counts->getCounts([])

Notes

$client->notes->create([
  "admin_id" => "21",
  "body" => "Text for my note",
  "user" => [
    "id" => "5310d8e8598c9a0b24000005"
  ]
]);
$client->notes->getNotes([
  "user_id" => "25"
]);
$client->notes->getNote("42");

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"]);