PHP code example of joinposter / intercom-integration-php
1. Go to this page and download the library: Download joinposter/intercom-integration-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
joinposter / intercom-integration-php example snippets
use Intercom\IntercomClient;
$client = new IntercomClient('<insert_token_here>');
$client = new IntercomClient('<insert_token_here>', null, ['Intercom-Version' => '1.1']);
/** Create a contact */
$client->contacts->create([
"type" => "user",
"email" => "[email protected]",
"custom_attributes" => ['foo' => 'bar']
]);
/** Update a contact */
$client->contacts->update("570680a8a1bcbca8a90001b9", [
"email" => "[email protected]",
"custom_attributes" => ['foo' => 'bar']
]);
/** Permanently delete a contact */
$client->contacts->deleteContact("570680a8a1bcbca8a90001b9");
/** Get a contact by ID */
$client->contacts->getContact("570680a8a1bcbca8a90001b9");
/** Search for contacts */
$query = ['field' => 'name', 'operator' => '=', 'value' => 'Alice'];
$client->contacts->search([
"query" => $query,
"sort" => ["field" => "name", "order" => "ascending"],
"pagination" => ["per_page" => 10]
]);
/** Get next page of conversation search results */
$client->contacts->nextSearch($query, $response->pages);
/** List all contacts */
$client->contacts->getContacts([]);
/** Create a user */
$client->users->create([
"email" => "[email protected]",
"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" => "[email protected]",
"custom_attributes" => ['foo' => 'bar']
]);
/** Archive a user by ID (i.e. soft delete) */
$client->users->archiveUser("570680a8a1bcbca8a90001b9");
/** Permanently delete a user */
$client->users->permanentlyDeleteUser("570680a8a1bcbca8a90001b9");
/** For more on the difference between archive and permanently deleting a user please see https://developers.intercom.com/reference#archive-a-user. */
/** Get a user by ID */
$client->users->getUser("570680a8a1bcbca8a90001b9");
/** Add companies to a user */
$client->users->create([
"email" => "[email protected]",
"companies" => [
[
"company_id" => "3"
]
]
]);
/** Remove companies from a user */
$client->users->create([
"email" => "[email protected]",
"companies" => [
[
"company_id" => "3",
"remove" => true
]
]
]);
/** Find a single user by email */
$client->users->getUsers(["email" => "[email protected]"]);
/** 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();
/**
* Create a lead
* See more options here: https://developers.intercom.io/reference#create-lead
*/
$client->leads->create([
"email" => "[email protected]",
"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" => "[email protected]",
"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" => "[email protected]"
]
]);
/**
* 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();
/** Update a visitor */
$client->visitors->update([
"user_id" => "8a88a590-e1c3-41e2-a502-e0649dbf721c",
"custom_attributes" => ['foo' => 'bar']
]);
/** Find a visitor by ID */
$client->visitors->getVisitor("570680a8a1bcbca8a90000a9");
/** Find a visitor by User ID */
$client->visitors->getVisitor("", ["user_id" => "8a88a590-e1c3-41e2-a502-e0649dbf721c"]);
/** Delete a visitor by ID */
$client->visitors->deleteVisitor("570680a8a1bcbca8a90000a9");
/** Convert a Visitor to a Lead */
$client->visitors->convertVisitor([
"visitor" => [
"user_id" => "8a88a590-e1c3-41e2-a502-e0649dbf721c"
],
"type" => "lead"
]);
/** Convert a Visitor to a User */
$client->visitors->convertVisitor([
"visitor" => [
"user_id" => "8a88a590-e1c3-41e2-a502-e0649dbf721c"
],
"user" => [
"email" => "[email protected]"
],
"type" => "user"
]);
/** List tags */
$client->tags->getTags();
/**
* Tag users
* See more options here: https://developers.intercom.io/reference#tag-or-untag-users-companies-leads-contacts
*/
$client->tags->tag([
"name" => "Test",
"users" => [
["id" => "1234"]
]
]);
/** List Segments */
$client->segments->getSegments();
/** View a segment */
$client->segments->getSegment("58a707924f6651b07b94376c");
/** View a segment with count */
$client->segments->getSegment("59c124f770e00fd819b9ce81", ["
/** Create an event */
$client->events->create([
"event_name" => "testing",
"created_at" => 1391691571,
"email" => "[email protected]",
"metadata" => [
"order_date" => 1392036272,
"stripe_invoice" => "inv_3434343434"
]
]);
/** View events for a user */
$client->events->getEvents(["email" => "[email protected]"]);
/** Create a company */
$client->companies->create([
"name" => "foocorp",
"company_id" => "3"
]);
/**
* Update a company
*/
$client->companies->update([
"name" => "foocorp",
"id" => "3"
]);
/** Create 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([]);
/** Get a company by ID */
$client->companies->getCompany("531ee472cce572a6ec000006");
/** List users belonging to a company by ID */
$client->companies->getCompanyUsers("531ee472cce572a6ec000006");
/** List users belonging to a company by company_id */
$client->companies->getCompanies(["type" => "user", "company_id" => "3"]);
/**
* Add companies to a contact with IDs
* First parameter is contact ID, second is company ID
*/
$client->companies->attachContact("570680a8a1bcbca8a90001b9", "531ee472cce572a6ec000006");
/**
* Detach company from contact
* First parameter is contact ID, second is company ID
*/
$client->companies->detachContact("570680a8a1bcbca8a90001b9", "531ee472cce572a6ec000006");
/** List admins */
$client->admins->getAdmins();
/**
* 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" => "[email protected]"
]
]);
/**
* 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"
])
/** Search for conversations (API version >= 2.0) */
$query = ['field' => 'updated_at', 'operator' => '>', 'value' => '1560436784'];
$client->conversations->search([
"query" => $query,
"sort" => ["field" => "updated_at", "order" => "ascending"],
"pagination" => ["per_page" => 10]
]);
/** Get next page of conversation search results (API version >= 2.0) */
$client->conversations->nextSearch($query, $response->pages);
/**
* Reply to a conversation
* 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"
]);
/**
* 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" => "[email protected]",
"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");
/**
* List counts
* See more options here: https://developers.intercom.io/reference#getting-counts
*/
$client->counts->getCounts([])
/** 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");
/** List teams */
$client->teams->getTeams();
/** Get a single Team by id */
$client->teams->getTeam("1188");