[go: up one dir, main page]

0% found this document useful (0 votes)
35 views34 pages

Apex Chat API

Uploaded by

Anil Shamra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views34 pages

Apex Chat API

Uploaded by

Anil Shamra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

ApexChat

ApexChat API
Documentation
Version 3.0

Sofia Agboatwalla, Jerod Venema


10/21/2015
Contents

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.

All URLs are assumed to start with the following base:

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)\/

All dates returned by the server are in UTC.

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.

Note: all POST bodies should be formatted as JSON string

Description Method URL Parameters Link to Example


List companies GET /companies/?start={start}&limit={limit}  start – the starting
value for the C# Example
paginated results
 limit – the PHP Example
number of
records to return
 filter- any filters
to apply on the
data. See the
section on
‘Filters’.

Load a specific GET /companies/{companyId}  companyId – the


company id of the company C# Example
to return
PHP Example

Update a company POST /companies/{companyId}  companyId – the


id of the company C# Example
to update
 POST body – the PHP Example
JSON
representation of
the company; see
below for details

Create a company POST /companies/create  POST body – the


JSON C# Example
representation of
the company; see PHP Example
below for details

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

Descripti Method URL Post Body Parameters Link to Examples


on
View GET /leads/?start={start}&limit={limit}  start – the starting value for the
most paginated results C# Example
recent  limit – the number of records to
leads return PHP Example
 filter- any filters to apply on the
data. See the section on ‘Filters’
View a G Sample URL: All parameters will be set up in the
E
summary of all portal. C# Example
leads T https://reports.apexchat.com//Servi
ces/DefaultService.svc/queueduserr PHP Example
eports/23709?format=json

View GET Sample URL: All parameters will be set up in the


billable portal. C# Example
leads https://reports.apexchat.com//Servi
ces/DefaultService.svc/queueduserr PHP Example
eports/23709?format=json

View GET /leads/{leadId}  leadId – the id of the lead to see


details details for C# Example
for a
specific PHP Example
lead

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

Description Method URL Post Body Parameters Link to


Examples

View traffic GET Sample URL: All parameters will be set


summarized up in the portal. C# Example
by company https://reports.apexchat.com//Services/DefaultServi
ce.svc/queueduserreports/23709?format=json PHP Example

View traffic GET Sample URL: All parameters will be set


summarized up in the portal. C# Example
by day https://reports.apexchat.com//Services/DefaultServi
ce.svc/queueduserreports/23709?format=json PHP Example

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

Description Method URL Parameters Link to Example

View GET Sample URL: All parameters will be set up


transcript in the portal. C# Example
for past https://reports.apexchat.com//
chats Services/DefaultService.svc/ PHP Example
queueduserreports/23709?for
mat=json

View GET /reports/transcripts/detail/{ch  chatId – the id of the


transcript atId} chat we want details C# Example
details – about
gets the full PHP Example
transcript
for a
specific
chat

Transcript report contains the following structure for each entry:

 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.

The "comparison" options are (starting with 0):

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# )

String URL = "http://api.apexchat.com/Services/ApexChatService.svc/companies/?start=0&limit=5”;

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

HttpWebResponse Response = (HttpWebResponse)request.GetResponse();

if (Response.StatusCode.ToString().ToLower() == "ok")
{
string contentType = Response.ContentType;
Stream content = Response.GetResponseStream();
StreamReader contentReader = new StreamReader(content);

using (var reader = new System.IO.StreamReader(


Response.GetResponseStream())) {
string responseText = reader.ReadToEnd();
Console.WriteLine(responseText);
Console.ReadLine();
}
}
}
catch (Exception ee) {
Console.Write(ee.Message.ToString());
Console.ReadLine();
}

16
List Companies ( PHP )
The following code will display the companies with the respective “start” and “limit values”

api.php refers to the PHP Template above.

require_once('api.php');

$edt = -240; // minutes offset from GMT

$api = new ApexChatApi('yourCompany','yourUsername','yourPassword');

$result = $api->getCompanies();

print_r($result);

17
Loading a Company with a Company ID ( C# )

String URL = "http://api.apexchat.com/Services/ApexChatService.svc/companies/{companyID}”;

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

HttpWebResponse Response = (HttpWebResponse)request.GetResponse();

if (Response.StatusCode.ToString().ToLower() == "ok")
{
string contentType = Response.ContentType;
Stream content = Response.GetResponseStream();
StreamReader contentReader = new StreamReader(content);

using (var reader = new System.IO.StreamReader(Response.GetResponseStream())) {


string responseText = reader.ReadToEnd();
Console.WriteLine(responseText);
Console.ReadLine();
}
}
}
catch (Exception ee) {
Console.Write(ee.Message.ToString());
Console.ReadLine();
}

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');

$api = new ApexChatApi('yourCompany','yourUsername','yourPassword');

$result = $api->getCompany();

print_r($result);

api.php refers to the PHP Template above.

The “getCompanies” method in the PHP Template needs to be replaced with the following function:

public function getCompany()


{
$json = $this->post('/companies/{companyId}’);
return json_decode($json);
}

The company ID goes at the end of the URL.

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

var javaScriptSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();


string data = javaScriptSerializer.Serialize(company);

request.Method = "POST";
request.ContentType = "application/json";
request.ContentLength = data.Length;

using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))


{
writer.Write(data);
}
request.Timeout = 65000;
HttpWebResponse Response = (HttpWebResponse)request.GetResponse();
using (StreamReader sr = new StreamReader(Response.GetResponseStream()))
{
string result = sr.ReadToEnd();
Console.WriteLine(result);
Console.Read();
}

public class Company {


public string address;
public string zip;
}

20
Updating a Company (PHP)
Code Snippet:

require_once('api.php');

$api = new ApexChatApi('yourCompany','yourUsername','yourPassword');

$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:

public function updateCompany($attributes)


{
$json = $this->post('/companies/{companyId}’ , json_encode($attributes));
return json_decode($json);
}

2. Change the method to “POST” in the PHP Template.

21
Creating a Company ( C# )
HttpWebRequest request =
(HttpWebRequest)HttpWebRequest.Create("http://api.apexchat.com/Services/ApexChatService.s
vc/companies/create");

Company company = new Company { companyName = "newCompany",


officeHoursTimezone="Mountain Standard Time",companyKey = "newcompany", hostId = 2, city
= "newcity", state = "newState", logLevel = 3, chatMode = 1, chatTheme=8,
invitationDisplayMode= 1,
invitationPosition=1, priority=2};
request.Headers["apexchat-company"] = "YourCompany";
request.Headers["apexchat-username"] = "YourUsername";
request.Headers["apexchat-password"] = "YourPassword";

var javaScriptSerializer = new JavaScriptSerializer();


string data = javaScriptSerializer.Serialize(company);

request.Method = "POST";
request.ContentType = "application/json";
request.ContentLength = data.Length;

using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))


{
writer.Write(data);
}
request.Timeout = 65000;

HttpWebResponse Response = (HttpWebResponse)request.GetResponse();

using (StreamReader sr = new StreamReader(Response.GetResponseStream()))


{
string result = sr.ReadToEnd();
Console.WriteLine(result);
Console.Read();
}
}
public class Company
{
public string companyName;
public string companyKey;
public int hostId;
public string city;
public string state;
public int logLevel;
public int chatMode;
public int chatTheme;
public int invitationDisplayMode;
public int invitationPosition;
public int priority;
public string officeHoursTimezone;
}

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:

public function createCompany($attributes)


{
$json = $this->post(‘/companies/create’ , json_encode($attributes));
return json_decode($json);
}

2. Change method to “POST” in the PHP Template

23
API Implementation for Managing Leads
View most recent leads ( C# )

String URL = "http://api.apexchat.com/Services/ApexChatService.svc/leads/?start=0&


limit=2”;

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

HttpWebResponse Response = (HttpWebResponse)request.GetResponse();

if (Response.StatusCode.ToString().ToLower() == "ok")
{
string contentType = Response.ContentType;
Stream content = Response.GetResponseStream();
StreamReader contentReader = new StreamReader(content);

using (var reader = new System.IO.StreamReader(Response.GetResponse


Stream())) {
string responseText = reader.ReadToEnd();
Console.WriteLine(responseText);
Console.ReadLine();
}
}
}
catch (Exception ee) {
Console.Write(ee.Message.ToString());
Console.ReadLine();
}

24
View most recent leads (PHP)

Code Snippet:

require_once('api.php');

$api = new ApexChatApi('yourCompany','yourUsername','yourPassword');

$result = $api->viewRecentLeads(array(
"companyKeys" => array("testcompany"), // you can add this line to filter down
to specific companies

))

print_r($result);

api.php refers to the PHP Template.

The “getCompanies” method in the PHP Template needs to be replaced with the following function:

public function viewRecentLeads($attributes)


{
$json = $this->post('/leads/?start={start}&limit={limit}’ ,
json_encode($attributes);
return json_decode($json);
}

25
View a Specific Lead ( C# )

String URL = "http://api.apexchat.com/Services/ApexChatService.svc/leads/{ID}”;

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

HttpWebResponse Response = (HttpWebResponse)request.GetResponse();

if (Response.StatusCode.ToString().ToLower() == "ok")
{
string contentType = Response.ContentType;
Stream content = Response.GetResponseStream();
StreamReader contentReader = new StreamReader(content);

using (var reader = new


System.IO.StreamReader(Response.GetResponseStream())) {
string responseText = reader.ReadToEnd();
Console.WriteLine(responseText);
Console.ReadLine();
}
}
}
catch (Exception ee) {
Console.Write(ee.Message.ToString());
Console.ReadLine();
}

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);
?>

api.php refers to the PHP Template.

The “getCompanies” method in the PHP Template needs to be replaced with the following function:

public function viewSpecificLead($attributes)


{
$json = $this->post('/leads/{leadId}’ , json_encode($attributes);
return json_decode($json);
}

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

HttpWebResponse Response = (HttpWebResponse)request.GetResponse();

if (Response.StatusCode.ToString().ToLower() == "ok")
{
string contentType = Response.ContentType;
Stream content = Response.GetResponseStream();
StreamReader contentReader = new StreamReader(content);

using (var reader = new


System.IO.StreamReader(Response.GetResponseStream())) {
string responseText = reader.ReadToEnd();
Console.WriteLine(responseText);
Console.ReadLine();
}
}
}
catch (Exception ee) {
Console.Write(ee.Message.ToString());
Console.ReadLine();
}

28
Viewing Transcript Details with ChatId (PHP)
Code Snippet:

require_once('api.php');

$api = new ApexChatApi('yourCompany','yourUsername','yourPassword');

$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:

public function viewTranscripts($attributes)


{
$json = $this->post('/reports/transcripts/detail/{chatId}’,null);
return json_decode($json);
}

2. Also change the base URL in the PHP Template to this:


https://reports.apexchat.com/Services/ApexChatService.svc

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”);

static void CallAPI(string url, string method = "GET")


{
HttpWebRequest request = null;
HttpWebResponse response = null;
request = (HttpWebRequest)WebRequest.Create(url);
request.Method = method;
request.ContentType = "application/json";
request.Timeout = 240000;
request.Headers.Add("apexchat-company", "yourCompany");
request.Headers.Add("apexchat-username", "yourUsername");
request.Headers.Add("apexchat-password", "yourPassword");
// get response
response = (HttpWebResponse)request.GetResponse();
var stream = response.GetResponseStream();
var streamReader = new StreamReader(stream);
var textResponse = streamReader.ReadToEnd();
Console.Write(textResponse);
Console.Read();
}//End of ‘CallAPI’ method

32
Report in PHP
api_reports.php refers to the PHP Reports Template:

<?php

require_once('api_reports.php');

$api = new ApexChatApi('yourCompany','yourUsername','yourPassword');

$result = $api->getLeads();

print_r($result);

?>

33

You might also like