Apex Chat API
Apex Chat API
ApexChat API
Documentation
Version 3.0
Request 2
Response 3
Dates 5
Authentication 6
Authorization 6
Managing Companies 7
Managing Leads 9
Viewing Transcripts 12
Filters 13
API Implementation in C# and PHP 14
API Implementation for Managing Companies 16
List Companies ( C# ) 16
List Companies ( PHP ) 17
Loading a Company with a Company ID ( C# ) 18
Loading a Company with a Company ID ( PHP ) 19
Updating a Company ( C# ) 20
Updating a Company (PHP) 21
Creating a Company ( C# ) 22
Creating a Company (PHP) 23
API Implementation for Managing Leads 24
View most recent leads ( C# ) 24
View most recent leads (PHP) 25
View a Specific Lead ( C# ) 26
View a Specific Lead (PHP) 27
Viewing Transcript Details with ChatId ( C# ) 28
Viewing Transcript Details with ChatId (PHP) 29
API Implementation for Reports 32
Report in C# 32
Report in PHP 33
1
Request
Requests to ApexChat are simply standard GET and POST requests.
PLEASE NOTE: A valid "Content-Type" header is required for all POST requests. Setting this value to
"text/json" is all that is necessary, but must exist for POST requests to function correctly.
In this document, it is assumed that when words appear in {curly} brackets, they refer to parameters
that can be set by the developer invoking the specific URL. Words with a question mark in {?curly}
brackets are optional.
http(s)://api.apexchat.com/Services/ApexChatService.svc/
Note that in order to avoid caching for GET request, you may need to add a no-cache parameter to your
request, such as shown in the example below.
Example:
http(s)://api.apexchat.com/Services/ApexChatService.svc/leads?start=0&limit=20&_nocache=123456
2
Response
Responses from ApexChat are JSON-encoded strings. Each response will have the following elements:
1. A “success” property, indicating if the request was successful
2. An “error” property, indicating the error, if the request was unsuccessful
3. A “data” property, containing the actual contents of the response
Additionally, if the request is for paginated data, the response will contain:
1. A “totalSize” property, indicating the total number of (un-paged) records
2. A “pageIndex” property, indicating the current page returned (0-based)
3. A “pageSize” property, indicating the maximum number of records that could be returned (note
that this does not necessarily correspond to the actual number of records returned, for example
it could have a value of “2” when returning the last 2 records on the last page of a group of
records)
3
Example:
{
"error":null,
"success":true,
"data":[
{
"chatId":300065,
"companyId":3,
"createdOn":"\/Date(1294684072953)\/",
"email":"jvenema@gmail.com",
"id":200002,
"leadType":1,
"make":"",
"model":"",
"name":"Jerod",
"notes":"a",
"notificationError":null,
"notificationState":3,
"phone":"919-300-5141",
"processedByCustomer":false,
"requestedLeadType":null,
"used":false
},
{
"chatId":300002,
"companyId":3,
"createdOn":"\/Date(1293812894410)\/",
"email":"jvenema@gmail.com",
"id":200001,
"leadType":1,
"make":"",
"model":"",
"name":"Jerod Venema",
"notes":"",
"notificationError":null,
"notificationState":3,
"phone":"919-368-5105",
"processedByCustomer":true,
"requestedLeadType":null,
"used":false
}
],
"pageIndex":0,
"pageSize":20,
"totalSize":2
}
4
Dates
Dates returned from the server are formatted in Microsoft standard formatting for JSON dates:
\/Date(1293812894410)\/
When making any POST requests, dates should be formatted using the MS format for JSON dates.
5
Authentication
Authentication is performed using standard HTTP headers. The headers that need to be set for each
request are:
apexchat-company
apexchat-username
apexchat-password
These headers must be sent with *every* request that uses the API. We recommend that you use
HTTPS for all requests, since your username and password are sent in plain text in the header of your
requests.
Authorization
If you attempt to set a property that you don’t have permission to change, the incoming property will be
ignored and the rest of the request will be processed as much as possible based on your permissions.
6
Managing Companies
The API provides a number of methods for retrieving and updating companies. See the following chart
for details. For POST methods, the company data structure can be seen below the table.
Companies contain the following structure (only partial properties are shown here). Almost all
properties can be modified using an UPDATE command. CompanyKey can be set during CREATE only.
Any items that can be set during UPDATE can be set during CREATE.
Updates to companies are partial. That is, any values NOT sent in the request will be left untouched.
active: true
addDetailedSubjectToLead: false
addReferrerToLead: false
addSearchEngineToLead: false
address: ""
7
afterHoursInvitationEnabled: false
agentIntelligenceEnabled: false
agentPickupWindow: 0
agentsEnabled: true
allowLeadResend: true
animationTime: 0
animationTimeAfter: 0
assignToAgents: true
autoPushUrls: false
chatHeaderTemplate: "Chatting with <#=agentName#>"
chatMode: 1
chatTheme: 8
chatThemeAfter: null
chatTitleTemplate: "<#=companyName#> Live Chat"
city: ""
companyKey: "FurnitureCompany"
companyName: "The Furniture Company"
companyType: 1
copyEntireTranscriptToLead: false
country: "United States"
crm: ""
crmParameters: [{codeName:appname, optional:1}, {codeName:actionsequence, optional:1},…]
directBilling: false
disableLeadEmails: false
domain: ""
enableLeadDenial: false
enableMobileSupport: false
enableRegionEditing: false
fixFlash: false
googleAnalyticsChatValue: 0
googleAnalyticsEventsEnabled: false
googleAnalyticsPagesEnabled: false
hasDedicatedMobileSite: false
hasInvalidEmails: false
hideOnClose: false
state: ""
supportedDevices: 1
useCrmEmail: false
useQuickConnectForCallerId: false
verificationEmailSent: false
verified: false
zip: ""
8
Managing Leads
Lead summary report contains the following structure for each entry:
attemptedCalls: 0
callIds: null
chatId: 3833488
companyKey: "chatService"
companyName: "The Chat Service"
completedCalls: 0
createdOn: "/Date(1393894190073)/"
denied: false
deniedDate: null
hostId: 1
keywords: ""
landingReferrer: "http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=4&ved=0C
HcQFjAD&url=http%3A%2F%2Fwww1.apexchat.com%2F&ei=fyIVU_nHLsbw0QGR-
4GgDA&usg=AFQjCNGdhaU71anvoMKggnouPikAlQy7Gg&sig2=bGmSDd48ByLvGYSEMR6TSA&bvm=bv.6228646
0,d.dmQ"
leadEmail: "sofia@apexchat.com"
leadId: 1888479
leadName: "Sofia"
leadNotes: " I was just looking to get an estimate on LiveChat services for a client of
mine. estimated cost per lead. Do you publish that information? I work for an
9
advertising agency The Advertising Company probably April or May no thanks, it's after
hours for me. I just had a minute and wanted to see about an estimated price per lead.
If someone wants to shoot me an email though that would be great. thanks! sure that
would be great. thanks!↵nope that's it, thanks!"
leadPhone: ""
leadTypeName: "Sales"
originalReferrer: "http://www1.someurl.com/plans/"
referrer: "http://www1.somerurl/how-it-works/"
requestedLeadType: null
username: null
Billable leads report contains the following structure for each entry:
agentLeads: 157
billableLeads: 157
companyKey: "chatCompany"
companyName: "The Chat Company"
operatorLeads: 0
sentByUserType: 2
10
Viewing Traffic
Traffic Summary by Company has the following structure for each entry:
active: true
billableLeads: 27
chats: 278
companyCreatedOn: "/Date(1296779665067)/"
companyKey: "furnitureCompany"
companyName: "The Furniture Company"
companySecureLeads: null
companyWebsite: null
invitedVisitors: 1923
leads: 52
otherLeads: 22
serviceLeads: 3
visits: 1925
Traffic Summary by Date has the following structure for each entry:
billableLeads: 3
chats: 6
date: "/Date(1393632000000)/"
invitedVisitors: 34
leads: 3
visits: 34
11
Viewing Transcripts
companyId: 2
companyKey: "chatCompany"
companyName: "The Chat Company"
createdOn: "/Date(1376514997007)/"
endedOn: "/Date(1376515044560)/"
landingReferrer: ""
leadId: 0
leadTypeId: 0
leadTypeName: null
location: "Unknown City, Unknown Region, (Unknown Country Code)"
originalReferrer: ""
pickedUpBy: "SofiaAgboatwalla"
pickedUpOn: "/Date(1376515040060)/"
referrer: "http://someUrl.net"
transcript: "[8/14/2013 9:17:20 PM] Jeff: Hello, thanks for contacting Frozen Mountain.
may I have your name? [8/14/2013 9:17:24 PM] System: All visitors have left the chat.
[8/14/2013 9:17:24 PM] System: The chat session has ended."
Transcript detail reports contain the full chat log, each entry containing the following structure:
chatId: 4034052
createdOn: "/Date(1397217405343)/"
id: 51621413
participantDisplayName: "Peter"
participantId: 13012857
text: "Hello, thanks for contacting Ferrari Driving School. My name is Peter, may I
have your name?"
12
userId: 519
Filters
The filter parameter may be passed along with the API call to restrict the data being returned based on
any fields.
The following two APIs listed in this document can be used with the filter parameter:
leads/?start={start}&limit={limit}
/companies/?start={start}&limit={limit}
The "filter" parameter is an array of JSON serialized objects. Currently, we only support combining those
filters with an "And" statement. Hence, you can pass multiple filters, and they'll restrict the data further.
Equals,
NotEquals,
Like,
NotLike,
GreaterThan,
GreaterOrEquals,
LessThan,
LessOrEquals
If you specify two date parameters, the comparison option is ignored, because the only sensible option is
"between".
The URL would look like similar to this to get the leads data between 2/14/15 and 3/3/15:
https://api.apexchat.com/Services/ApexChatService.svc/leads/?_dc=1425398679778&limit=20&filter=[{"propertyName":"create
dOn","propertyValue1":"2015-02-24T08:00:00","propertyValue2":"2015-03-03T08:00:00","comparison":0}]
For getting data on companies located in Australia, the Url would look similar to this:
https://api.apexchat.com/Services/ApexChatService.svc/companies/?_dc=1425398679778&limit=20&filter=[{"propertyName":"
country","propertyValue1":"Australia","propertyValue2":"","comparison":0}]
13
API Implementation in C# and PHP
PHP Template
The highlighted portions in blue will change based on the type of call. This template will be
used along with the code snippet with each type of call.
<?php
class ApexChatApi
{
private $base = "http://api.apexchat.com/Services/ApexChatService.svc";
private $company = "";
private $username = "";
private $password = "";
public function __construct($company, $username, $password)
{
$this->company = $company;
$this->username = $username;
$this->password = $password;
}
public function getCompanies()
{
$json = $this->post('/companies/?start=0&limit=5');
return json_decode($json);
}
public function getMSTime($timestamp)
{
return "/Date(" . ($timestamp * 1000) . ")/";
}
private function post($partial)
{
return $this->_post($this->base . $partial, $data , array(
'Content-Type' => 'text/json',
'apexchat-company' => $this->company,
'apexchat-username' => $this->username,
'apexchat-password' => $this->password
));
}
private function _post($url, $data, $optional_headers = null)
{
$params = array('http' => array(
'method' => 'GET',
'content' => $data
));
if ($optional_headers !== null) {
$header_text = array();
foreach($optional_headers as $key => $value) {
$header_text[] = $key . ': ' . $value;
14
}
$params['http']['header'] = implode("\r\n", $header_text);
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
$w = stream_get_wrappers();
echo 'openssl: ', extension_loaded ('openssl') ?
'yes':'no', "\n";
echo 'https wrapper: ', in_array('https', $w) ?
'yes':'no', "\n";
die("Problem with $url, $php_errormsg. If openssl or https
wrapper (listed above this message) is 'no', then you need to instal/enable SSL for
your PHP installation");
}//end of if statement
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url,
$php_errormsg");
}
return $response;
}
}//end of class
?>
15
API Implementation for Managing Companies
List Companies ( C# )
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = "GET";
request.Headers["apexchat-company"] = “yourCompany”;
request.Headers["apexchat-username"] = "yourUsername”;
request.Headers["apexchat-password"] = "yourPassword";
if (Response.StatusCode.ToString().ToLower() == "ok")
{
string contentType = Response.ContentType;
Stream content = Response.GetResponseStream();
StreamReader contentReader = new StreamReader(content);
16
List Companies ( PHP )
The following code will display the companies with the respective “start” and “limit values”
require_once('api.php');
$result = $api->getCompanies();
print_r($result);
17
Loading a Company with a Company ID ( C# )
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = "GET";
request.Headers["apexchat-company"] = "yourCompany";
request.Headers["apexchat-username"] = "yourUsername";
request.Headers["apexchat-password"] = "yourPassword";
if (Response.StatusCode.ToString().ToLower() == "ok")
{
string contentType = Response.ContentType;
Stream content = Response.GetResponseStream();
StreamReader contentReader = new StreamReader(content);
18
Loading a Company with a Company ID ( PHP )
The following code allows you to load a company using the company ID.
Code Snippet:
require_once('api.php');
$result = $api->getCompany();
print_r($result);
The “getCompanies” method in the PHP Template needs to be replaced with the following function:
19
Updating a Company ( C# )
String URL =
"http://api.apexchat.com/Services/ApexChatService.svc/companies/{companyID}”;
Company company = new Company { address = “103 Blaney Ave" , zip = “95014” };
request.Headers["apexchat-company"] = "yourCompany";
request.Headers["apexchat-username"] = "yourUsername";
request.Headers["apexchat-password"] = "yourPassword";
request.Method = "POST";
request.ContentType = "application/json";
request.ContentLength = data.Length;
20
Updating a Company (PHP)
Code Snippet:
require_once('api.php');
$result = $api->updateCompany(array( "address" => "103 Blaney Ave" , "zip" => "95014"
));
print_r($result);
api.php refers to the PHP Template. The following changes need to be applied to the PHP Template:
1. The “getCompanies” method in the PHP Template needs to be replaced with the following function:
21
Creating a Company ( C# )
HttpWebRequest request =
(HttpWebRequest)HttpWebRequest.Create("http://api.apexchat.com/Services/ApexChatService.s
vc/companies/create");
request.Method = "POST";
request.ContentType = "application/json";
request.ContentLength = data.Length;
22
Creating a Company (PHP)
Code Snippet:
<?php
require_once(‘api.php’);
$api = new ApexChatApi('yourCompany','yourUsername','yourPassword');
$result = $api->createCompany(array( “companyName” => “newCompany” , “companyKey” =>
“newCompanyKey”, “city” => “newCity” , “zip” => “newZip” , “state” => “newState”,
“logLevel”=>3, “hostId”=>yourHostId, “chatMode”=>1, “chatTheme”=>8,
“invitationDisplayMode”=>1, “invitationPosition”=>1, “priority”=>2
));
print_r($result);
?>
api.php refers to the PHP Template. The following changes need to be applied to the PHP Template:
1. The “getCompanies” method in the PHP Template needs to be replaced with the following
function:
23
API Implementation for Managing Leads
View most recent leads ( C# )
try
{
HttpWebRequest request= (HttpWebRequest)HttpWebRequest.Create(URL);
request.Method = "GET";
request.Headers["apexchat-company"] = "yourCompany";
request.Headers["apexchat-username"] = "yourUsername";
request.Headers["apexchat-password"] = "yourPassword";
if (Response.StatusCode.ToString().ToLower() == "ok")
{
string contentType = Response.ContentType;
Stream content = Response.GetResponseStream();
StreamReader contentReader = new StreamReader(content);
24
View most recent leads (PHP)
Code Snippet:
require_once('api.php');
$result = $api->viewRecentLeads(array(
"companyKeys" => array("testcompany"), // you can add this line to filter down
to specific companies
))
print_r($result);
The “getCompanies” method in the PHP Template needs to be replaced with the following function:
25
View a Specific Lead ( C# )
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = "GET";
request.Headers["apexchat-company"] = "yourCompany";
request.Headers["apexchat-username"] = "yourUsername";
request.Headers["apexchat-password"] = "yourPassword";
if (Response.StatusCode.ToString().ToLower() == "ok")
{
string contentType = Response.ContentType;
Stream content = Response.GetResponseStream();
StreamReader contentReader = new StreamReader(content);
26
View a Specific Lead (PHP)
Code Snippet:
<?php
require_once(‘api.php’);
$api = new ApexChatApi('yourCompany','yourUsername','yourPassword');
$result = $api->viewSpecificLead(array(
"companyKeys" => array("testcompany"),
));
print_r($result);
?>
The “getCompanies” method in the PHP Template needs to be replaced with the following function:
27
API Implementation for Viewing Transcripts
Viewing Transcript Details with ChatId ( C# )
String URL
="http://reports.apexchat.com/Services/ApexChatService.svc/leads/{chatID}”;
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = "GET";
request.Headers["apexchat-company"] = "yourCompany";
request.Headers["apexchat-username"] = "yourUsername";
request.Headers["apexchat-password"] = "yourPassword";
if (Response.StatusCode.ToString().ToLower() == "ok")
{
string contentType = Response.ContentType;
Stream content = Response.GetResponseStream();
StreamReader contentReader = new StreamReader(content);
28
Viewing Transcript Details with ChatId (PHP)
Code Snippet:
require_once('api.php');
$result = $api->viewTranscripts();
print_r($result);
api.php refers to the PHP Template. The following changes need to be applied to the PHP Template:
1. The “getCompanies” method in the PHP Template needs to be replaced with the
following function:
29
PHP Reports Template
The highlighted portions in blue will change based on the type of call.
<?php
class ApexChatApi
{
private $base =
"http://reports.apexchat.com/Services/DefaultService.svc";
private $company = "";
private $username = "";
private $password = "";
public function __construct($company, $username, $password)
{
$this->company = $company;
$this->username = $username;
$this->password = $password;
}
public function getCompanies()
{
$json = $this->post('/queueduserreports/23709?format=json,
json_encode($attributes) );
return json_decode($json);
}
public function getMSTime($timestamp)
{
return "/Date(" . ($timestamp * 1000) . ")/";
}
private function post($partial)
{
return $this->_post($this->base , $partial, array(
'Content-Type' => 'text/json',
'apexchat-company' => $this->company,
'apexchat-username' => $this->username,
'apexchat-password' => $this->password
));
}
private function _post($url, $data, $optional_headers = null)
{
$params = array('http' => array(
'method' => 'GET',
'content' => $data
));
if ($optional_headers !== null) {
$header_text = array();
foreach($optional_headers as $key => $value) {
$header_text[] = $key . ': ' . $value;
30
}
$params['http']['header'] = implode("\r\n", $header_text);
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
$w = stream_get_wrappers();
echo 'openssl: ', extension_loaded ('openssl') ?
'yes':'no', "\n";
echo 'https wrapper: ', in_array('https', $w) ?
'yes':'no', "\n";
die("Problem with $url, $php_errormsg. If openssl or https
wrapper (listed above this message) is 'no', then you need to instal/enable SSL for
your PHP installation");
}//end of if statement
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url,
$php_errormsg");
}
return $response;
}
}//end of class
?>
31
API Implementation for Reports
In the Portal, "Reporting" area, open the report which you want to be notified about. Simply plug in
the URL at which you wish to be notified (use the Notification Endpoint field). This URL will be hit with a
GET request with a "jsonUrl" parameter. You will need to make a GET request to that URL for accessing
the report as a JSON object which you can process into your system however you want. “xlsxUrl” and
“csvUrl” are also available.
Report in C#
CallAPI(“https://reports.apexchat.com/Services/DefaultService.svc/queueduserreports/2
3709?format=json” , "GET”);
32
Report in PHP
api_reports.php refers to the PHP Reports Template:
<?php
require_once('api_reports.php');
$result = $api->getLeads();
print_r($result);
?>
33