Incoming Leads
The state of the Incoming leads includes all calls from integrations: telephony and forms for the site that have not yet been processed by the user (a lead or contact has been created). The user can accept the Incoming lead, or reject it. If accepted, a lead will be created, as well as a contact and / or company, if the relevant information is in the request. If the request is rejected, the data will be deleted.
Adding to the Incoming Leads
The method allows you to add unparsed one by one or batch.
Common parameters
Parameter | Type | Description |
---|---|---|
add/source_name require |
string | Name of the source of the request |
add/source_uid require |
string | Unique request identifier |
add/pipeline_id | int | Pipeline ID, if the parameter is not passed, then the request will be added to the unshaped primary pipeline |
add/incoming_lead_info | array | An array containing information about the received |
add/incoming_entities require |
array | An array containing information about the created entity elements. It is mandatory, because after the adparameter of the unseparated, the corresponding elements of the entity will be created. |
add/incoming_entities/leads | array | An array containing information for creating a new lead. Can contain all the parameters and Custom fieldss available for leads for the current account. |
add/incoming_entities/contacts | array | An array containing information for creating a new contact. Can contain all the parameters and Custom fieldss available for contacts for the current account. |
add/incoming_entities/companies | array | An array containing information for creating a new company. Can contain all the parameters and Custom fieldss available to companies for the current account. |
A new request in the incoming leads can be one of the available types:
-
Incoming call (sip)
-
Web Form
Add an request from an incoming call:
Method URL
POST / api / v2 / incoming_leads / sip
Parameters for sip
Parameter | Type | Description |
---|---|---|
add/incoming_lead_info/to require |
int | ID of the user who received the call |
add/incoming_lead_info/from require |
string | External phone number from which the call was received |
add/incoming_lead_info/date_call require |
timestamp | Date and time of call |
add/incoming_lead_info/duration require |
int | Call duration |
add/incoming_lead_info/link require |
string | Link to record a call |
add/incoming_lead_info/service_code require |
string | The code of the widget or service through which the call was made |
add/incoming_lead_info/uniq require |
string | Unique call code |
add/incoming_lead_info/add_note require |
bool | Flag, if this parameter is passed, then after the acceptance of the request in the created entities an event about the made call will be added. |
Response example
{
add: [
{
source_name: "EcoSport",
source_uid: "a1fee7c0fc436088e64ba2e8822ba2b3",
created_at: "1510261200",
pipeline_id: "41563",
incoming_entities: {
leads: [
{
name: "Maintenance of chain saws",
created_at: "1509483600",
status_id: "13667502",
responsible_user_id: "504141",
price: "1000",
tags: "MT, services",
notes: [
{
note_type: "7",
element_type: "lead",
text: "Send a duplicate of the contract"
}
],
custom_fields: [
{
id: "4399917",
values: [
"3692247",
"3692248"
]
}
]
}
],
contacts: [
{
name: "Jason Nash",
custom_fields: [
{
id: "4396818",
values: [
{
value: "+19457898713",
enum: "WORK"
}
]
},
{
id: "4396819",
values: [
{
value: "email@email.com",
enum: "WORK"
}
]
},
{
id: "4400115",
values: [
{
value: "Madison street, 1",
subtype: "address_line_1"
},
{
value: "Washington",
subtype: "city"
},
{
value: "20011",
subtype: "zip"
},
{
value: "US",
subtype: "country"
}
]
}
],
responsible_user_id: "504141",
date_create: "1509483600"
}
],
companies: [
{
name: "EcoSport"
}
]
},
incoming_lead_info: {
to: "41565",
from: "+19456153101",
date_call: "1509483600",
duration: "54",
link: "https://www.example.com/records/2017/11/01/98431.mp3",
service_code: "CkKwPam6",
uniq: "a1fee7c0fc436088e64ba2e8822ba2b3ewrw",
add_note: "We agreed on cooperation"
}
}
]
}
In the preview of the request card (received through the web form), information received from the entity arrays (add / incoming_entities) is displayed in the incoming leads. In this case, it is necessary to take into account the existing priority of obtaining information from these arrays by type of entity.
Priority of entity types, for displaying information in the request form:
-
Contact
-
Lead
-
Customer
To display in the request form, the following information is taken.
-
Entity element name
-
Tags
-
Custom fieldss and their meanings
Adding an request from the web form:
Method URL
POST / api / v2 / incoming_leads / form
Parameters for the web form:
Parameter | Type | Description |
---|---|---|
add/incoming_lead_info/form_id require |
int | Form identifier |
add/incoming_lead_info/form_page require |
string | The address of the page on which the form is located |
add/incoming_lead_info/ip require |
string | IP address from which the request was received |
add/incoming_lead_info/service_code require |
string | Widget or service code |
add/incoming_lead_info/form_name | string | Form name |
add/incoming_lead_info/form_send_at | timestamp | Date and time of sending data via form |
add/incoming_lead_info/referer | string | The parameter contains information from where to go to the page where the form is located. |
Response example
{
add: [
{
source_name: "Company LLC",
source_uid: "a1fee7c0fc436088e64ba2e8822ba2b3",
pipeline_id: "41563",
incoming_entities: {
leads: [
{
name: "Maintenance of rotary hammers",
created_at: "1509483600",
status_id: "13667502",
responsible_user_id: "504141",
sale: "45000",
tags: "MT, services",
notes: [
{
note_type: "7",
element_type: "lead",
text: "Send an invoice"
}
],
custom_fields: [
{
id: "4399917",
values: [
"3692247",
"3692248"
]
}
]
}
],
contacts: [
{
name: "Jeremy Paul",
custom_fields: [
{
id: "4396818",
values: [
{
value: "+19451456510",
enum: "WORK"
}
]
},
{
id: "4396819",
values: [
{
value: "email@email.com",
enum: "WORK"
}
]
},
{
id: "4400115",
values: [
{
value: "Madison street, 1",
subtype: "address_line_1"
},
{
value: "Washington",
subtype: "city"
},
{
value: "20011",
subtype: "zip"
},
{
value: "US",
subtype: "country"
}
]
}
],
responsible_user_id: "504141",
created_at: "1509483600"
}
],
companies: [
{
name: "Company LLC"
}
]
},
incoming_lead_info: {
form_id: "159783",
form_page: "example.com",
ip: "127.0.0.1",
service_code: "QkKwSam8",
form_name: "Leave a request",
form_send_at: "1509483600",
referer: http://example.com/index.php?ref=103719
}
}
]
}
Response parameters
Parameter | Type | Description |
---|---|---|
status | string | Adding status: success or fail |
data | array | An array containing the unique identifiers of the added orders in the Incoming Leads |
_links | array | Array containing information about the request |
_links/self | array | An array containing information about the current request |
_links/self/href | string | Relative URL of the current request |
_links/self/method | string | Method of the current request |
error | string | Description of the cause of the error. Transmitted only when an error occurs. |
error_code | int | Error code |
Response parameters
{
status: "success",
data: {
"561a8a8b7d7a8cbc440965903605a27685a9ec37317bc395636a481e31f7"
},
_links: {
self: {
href: "/api/v2/incoming_leads/form?login=example@example.com&api_key=24db154826a13a988893be1da61",
method: "post"
}
}
}
Example integration
/* First, we need to initialize the data needed to compose the query. */
$data = array (
'add' =>
array (
0 =>
array (
'source_name' => 'Company LLC',
'source_uid' => 'a1fee7c0fc436088e64ba2e8822ba2b3',
'pipeline_id' => '41563',
'created_at' => '1509483600',
'incoming_entities' =>
array (
'leads' =>
array (
0 =>
array (
'name' => 'Maintenance of the chainsaw',
'created_at' => '1509483600',
'status_id' => '13667502',
'responsible_user_id' => '504141',
'price' => '1000',
'tags' => 'MT, services'',
'custom_fields' =>
array (
0 =>
array (
'id' => '4399917',
'values' =>
array (
0 => '3692247',
1 => '3692248',
),
),
1 =>
array (
'id' => '4399923',
'values' =>
array (
0 =>
array (
'value' => 'Madison st. 1',
'subtype' => 'address_line_1',
),
1 =>
array (
'value' => 'Washington',
'subtype' => 'city',
),
2 =>
array (
'value' => '20011',
'subtype' => 'zip',
),
3 =>
array (
'value' => 'US',
'subtype' => 'country',
),
),
),
),
),
),
'contacts' =>
array (
0 =>
array (
'name' => 'Jason Nash',
'custom_fields' =>
array (
0 =>
array (
'id' => '4396818',
'values' =>
array (
0 =>
array (
'value' => '+19457898713',
'enum' => 'WORK',
),
),
),
1 =>
array (
'id' => '4396819',
'values' =>
array (
0 =>
array (
'value' => 'email@email.com',
'enum' => 'WORK',
),
),
),
),
'responsible_user_id' => '504141',
),
),
'companies' =>
array (
0 =>
array (
'name' => 'Company LLC',
),
),
),
'incoming_lead_info' =>
array (
'to' => '41565',
'from' => '+19456153101',
'date_call' => '1509483600',
'duration' => '56',
'link' => 'https://www.example.com/records/2017/11/01/98431.mp3',
'service_code' => 'CkKwPam6',
'uniq' => 'a1fee7c0fc436088e64ba2e8822ba2b3ewrw',
'add_note' => 'Send a duplicate of the contract',
),
),
),
);
$subdomain='test'; #Our account is a subdomain
#Generate a link for the request
$link='https://'.$subdomain.'.amocrm.com/api/v2/incoming_leads/sip';
/* Note that you can pass other parameters in the reference that affect the output (see documentation).
Therefore, we can replace the link given above with one of the following, or combine the parameters in the way that you want. */
$link='https://'.$subdomain.'.amocrm.com/api/v2/incoming_leads/sip?api_key='.$api_key.'&login='.$login;
/* We need to initiate a request to the server. We use the cURL library (supplied as part of PHP). More about work with this library you can read in the manual. */
$curl=curl_init(); #Save the cURL session descriptor
#Set the necessary parameters for the cURL session
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_USERAGENT,'amoCRM-API-client/1.0');
curl_setopt($curl,CURLOPT_HTTPHEADER,['Accept: application/json']);
curl_setopt($curl,CURLOPT_URL,$link);
curl_setopt($curl,CURLOPT_HEADER,false);
curl_setopt($curl,CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,0);
$out=curl_exec($curl); #Initiate a request to the API and save the response to a variable
$code=curl_getinfo($curl,CURLINFO_HTTP_CODE);
curl_close($curl);
/*Now we can process the response received from the server. This is an example. You can process the data in your own way. */
$code=(int)$code;
$errors=array(
301=>'Moved permanently',
400=>'Bad request',
401=>'Unauthorized',
403=>'Forbidden',
404=>'Not found',
500=>'Internal server error',
502=>'Bad gateway',
503=>'Service unavailable'
);
try
{
#If the response code is not 200, 201 or 204, we return an error message
if(!in_array($code, [200, 201, 204]))
throw new Exception(isset($errors[$code]) ? $errors[$code] : 'Undescribed error',$code);
}
catch(Exception $E)
{
die('Error: '.$E->getMessage().PHP_EOL.'Error code: '.$E->getCode());
}
/*
The data is obtained in the JSON format, therefore, in order to obtain readable data,
We will have to translate the response into a format that PHP understands
*/
$Response=json_decode($out,true);
$Response=$Response['data'];
Acceptance of incoming leads
Method for accepting incoming requests.
Method URL
POST / api / v2 / incoming_leads / accept
Parameters
Parameter | Type | Description |
---|---|---|
accept | array(string) | An array of unique identifiers (uid) of unsorted orders |
user_id | int | id of the account user, on behalf of which leads / contacts / companies will be created |
status_id | int | The status of leads that will be created as a result of the adoption of an Incoming lead |
Response example
{
accept: [
"6d054b50e0769b0d8bdaed73901e6a544ba329aa1d0d2f0d25fde025398e",
"56df4sg6dfs5g1f56bdaed65498e6asd56f4ds65f4SDds6f54sd65f4d89q"
],
user_id: "504141",
status_id: "142"
}
Response parameters
Parameter | Type | Description |
---|---|---|
status | string | Adding status: success or fail |
data | array | An array containing the unique identifiers of the added orders in the Incoming Leads |
data//companies | array | An array containing the id of the created company |
data//leads | array | An array containing the id of the created leads |
data//contacts | array | An array containing the id of the created contacts |
_links | array | Array containing information about the request |
_links/self | array | An array containing information about the current request |
_links/self/href | string | Relative URL of the current request |
_links/self/method | string | Method of the current request |
error | string | Description of the cause of the error. Transmitted only when an error occurs. |
Response Headers contains the following headers:
-
Content-Type:application/hal+json
-
Runtime-Timestamp: 1508320306
Response example
{
status: "success",
data: {
561a8a8b7d7a8cbc440965903605a27685a9ec37317bc395636a481e31f7: {
companies: [
1099388
],
leads: [
1090596
],
contacts: [
1099389
]
}
},
_links: {
self: {
href: "/api/v2/incoming_leads/accept?login=dhnikolas2@gmail.com&api_key=24dbfd65b23ff2ea13a988893be1da61",
method: "post"
}
}
}
To accept an unparsed, it is necessary to describe an array containing request identifiers. Also, you must specify the user id as an element of the $data array. You can specify the status of the resulting lead.
Example integration:
$data=array(
'accept' => array(
'6d054b50e0769b0d8bdaed73901e6a544ba329aa1d0d2f0d25fde025398e',
'56df4sg6dfs5g1f56bdaed65498e6asd56f4ds65f4SDds6f54sd65f4d89q'
),
'user_id' => 102525,
'status_id' => 1023486
);
$subdomain='test'; #Our account is a subdomain
#Generate a link for the request
$link='https://'.$subdomain.'.amocrm.com/api/v2/incoming_leads/accept/';
/* Note that you can pass other parameters in the reference that affect the output (see documentation).
Therefore, we can replace the link given above with one of the following, or combine the parameters in the way that you want. */
$link='https://'.$subdomain.'.amocrm.com/api/v2/incoming_leads/accept?api_key='.$api_key.'&login='.$login;
/* We need to initiate a request to the server. We use the cURL library (supplied as part of PHP). More about work with this library you can read in the manual. */
$curl=curl_init(); #Save the cURL session descriptor
#Set the necessary parameters for the cURL session
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_USERAGENT,'amoCRM-API-client/1.0');
curl_setopt($curl,CURLOPT_HTTPHEADER,['Accept: application/json']);
curl_setopt($curl,CURLOPT_URL,$link);
curl_setopt($curl,CURLOPT_HEADER,false);
curl_setopt($curl,CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,0);
$out=curl_exec($curl); #Initiate a request to the API and save the response to a variable
$code=curl_getinfo($curl,CURLINFO_HTTP_CODE);
curl_close($curl);
/* Now we can process the response received from the server. This is an example. You can process the data in your own way. */
$code=(int)$code;
$errors=array(
301=>'Moved permanently',
400=>'Bad request',
401=>'Unauthorized',
403=>'Forbidden',
404=>'Not found',
500=>'Internal server error',
502=>'Bad gateway',
503=>'Service unavailable'
);
try
{
#If the response code is not 200, 201 or 204, we return an error message
if(!in_array($code, [200, 201, 204])
throw new Exception(isset($errors[$code]) ? $errors[$code] : 'Undescribed error',$code);
}
catch(Exception $E)
{
die('Error: '.$E->getMessage().PHP_EOL.'Error code: '.$E->getCode());
}
Declining of incoming leads
Method for rejecting unlisted requests.
Method URL
POST / api / v2 / incoming_leads / decline
Parameters
Parameter | Type | Description |
---|---|---|
decline | array | Array of unique identifiers (uid) of unsorted orders |
user_id | int | id of the user on whose behalf the request will be rejected |
Response example
{
decline: [
"6d054b50e0769b0d8bdaed73901e6a544ba329aa1d0d2f0d25fde025398e",
"56df4sg6dfs5g1f56bdaed65498e6asd56f4ds65f4SDds6f54sd65f4d89q"
],
user_id: "504141"
}
Response parameters:
Parameter | Type | Description |
---|---|---|
status | string | Adding status: success or fail |
data | array | An array containing unique request identifiers in the Incoming Leads |
_links | array | Array containing information about the request |
_links/self | array | An array containing information about the current request |
_links/self/href | string | Relative URL of the current request |
_links/self/method | string | Method of the current request |
error | string | Description of the cause of the error. Transmitted only when an error occurs. |
Response Headers contains the following headers:
-
Content-Type:application/hal+json
-
Runtime-Timestamp: 1508320306
Response example
{
status: "success",
data: {
86c4ff85844722b75fcd0bed7b6fe0ac099a3a1e20e70823dcd634fc8e69: false
},
_links: {
self: {
href: "/api/v2/incoming_leads/decline?login=example@example.com&api_key=7d4cebf7b176a2c3dc84b365eea7e1260af",
method: "post"
}
}
}
To reject an unparsed, it is necessary to describe an array containing the identifiers of the claims. You must also specify the user id.
Example integration
$data=array(
'decline' => array(
'6d054b50e0769b0d8bdaed73901e6a544ba329aa1d0d2f0d25fde025398e',
'56df4sg6dfs5g1f56bdaed65498e6asd56f4ds65f4SDds6f54sd65f4d89q'
),
'user_id' => 102525
);
$subdomain='test'; #Our account is a subdomain
#Generate a link for the request
$link='https://'.$subdomain.'.amocrm.com/api/v2/incoming_leads/decline';
/* Note that you can pass other parameters in the reference that affect the output (see documentation).
Therefore, we can replace the link given above with one of the following, or combine the parameters in the way that you want. */
$link='https://'.$subdomain.'.amocrm.com/api/v2/incoming_leads/decline?api_key='.$api_key.'&login='.$login;
/* We need to initiate a request to the server. We use the cURL library (supplied as part of PHP). More about work with this library you can read in the manual. */
$curl=curl_init(); #Save the cURL session descriptor
#Set the necessary parameters for the cURL session
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_USERAGENT,'amoCRM-API-client/1.0');
curl_setopt($curl,CURLOPT_HTTPHEADER,['Accept: application/json']);
curl_setopt($curl,CURLOPT_URL,$link);
curl_setopt($curl,CURLOPT_HEADER,false);
curl_setopt($curl,CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,0);
$out=curl_exec($curl); #Initiate a request to the API and save the response to a variable
$code=curl_getinfo($curl,CURLINFO_HTTP_CODE);
curl_close($curl);
/* Now we can process the response received from the server. This is an example. You can process the data in your own way. */
$code=(int)$code;
$errors=array(
301=>'Moved permanently',
400=>'Bad request',
401=>'Unauthorized',
403=>'Forbidden',
404=>'Not found',
500=>'Internal server error',
502=>'Bad gateway',
503=>'Service unavailable'
);
try
{
#If the response code is not 200, 201 or 204, we return an error message
if(!in_array($code, [200, 201, 204])
throw new Exception(isset($errors[$code]) ? $errors[$code] : 'Undescribed error',$code);
}
catch(Exception $E)
{
die('Error: '.$E->getMessage().PHP_EOL.'Error code: '.$E->getCode());
}
List of incoming leads
A method for obtaining a list of incoming leads with the possibility of filtering and paging. Restriction on data returned on one page (offset) – 500 requests.
Method URL
GET / api / v2 / incoming_leads
Query Parameters
Parameter | Description |
---|---|
page_size | Number of selectable rows (system limit 500) |
page | Selection Page |
categories | An array containing the categories for which you want to select (sip, mail, forms, chat) |
order_by | An array of one element. Key – field for sorting (created_at, for example), value (asc, desc) – sorting direction |
pipeline_id | The identifier of the pipeline from which to select |
Response parameters
Parameter | Type | Description |
---|---|---|
_embedded | array | An array containing information adjacent to the query |
_embedded/items | array | An array containing information for each individual element |
source_name require |
string | Name of the source of the request |
uid require |
string | The unique identifier of the request |
created_at | timestamp | Date and time the request was created |
category | string | Category, sip or form |
incoming_entities/leads | array | An array containing information for creating a new lead. Can contain all the parameters and Custom fieldss available to “leads” on the account. |
incoming_entities/contacts | array | An array containing information for creating a new contact. Can contain all the parameters and Custom fieldss available to “Contacts” on the account. |
incoming_entities/companies | array | An array containing information for creating a new company. Can contain all the parameters and Custom fieldss available to “Companies” on the account. |
incoming_lead_info/to | int | The identifier of the user who received the call |
incoming_lead_info/from | string | External phone number |
incoming_lead_info/date | timestamp | Date and time of the call |
incoming_lead_info/duration | int | Call duration |
incoming_lead_info/link | string | Link to call recording |
incoming_lead_info/service_code | string | The code of the widget or service through which the call was made |
incoming_lead_info/form_id | int | Form identifier |
incoming_lead_info/form_page | string | The address of the page on which the form is located |
incoming_lead_info/ip | string | The IP address on which the form is located |
incoming_lead_info/form_name | string | Form name |
incoming_lead_info/form_send_at | timestamp | Date and time of sending data via form |
incoming_lead_info/referer | string | The parameter contains information from where to go to the page where the form is located. |
_links | array | Array containing information about the request |
_links/self | array | An array containing information about the current request |
_links/self/href | string | Relative URL of the current request |
_links/self/method | string | Method of the current request |
Response Headers contains the following headers:
-
Content-Type:application/hal+json
-
Runtime-Timestamp: 1508320306
Response example
{
_links: {
self: {
href: "/api/v2/incoming_leads?login=name@team.amocrm.com&api_key=xxxxxx",
method: "get"
}
},
_embedded: {
items: [
{
category: "sip",
uid: "86c4ff85844722b75fcd74699b5a1ce474f7f73e272395b301ca87b36a33",
source_name: "686",
created_at: 1509609502,
incoming_lead_info: {
from: "15315",
to: "8152",
date: 1509570000,
duration: "50",
link: "example.com",
service_code: "CkKwPam6"
},
incoming_entities: {
leads: [
{
name: "Lead"
}
]
}
},
{
category: "form",
uid: "3b89a37ee72c329753750d9c3b7613a96aefa88e7d6065e383986e353d17",
source_name: "eterdgf",
created_at: 1509610029,
incoming_lead_info: {
form_id: "154613",
form_name: "Application",
form_page: "example.com",
ip: "48221",
form_send_at: 1509610030,
referer: null
},
incoming_entities: {
leads: [
{
name: "Lead",
custom_fields: [
{
id: 4399916,
values: [
{
value: "3692245"
}
],
is_system: false
}
]
}
]
}
}
]
}
}
Example integration
/* First, we need to initialize the data needed to compose the query. */
$subdomain='test'; #Our account is a subdomain
#Generate a link for the request
$link='https://'.$subdomain.'.amocrm.com/api/v2/incoming_leads';
/* Note that you can pass other parameters in the reference that affect the output (see documentation).
Therefore, we can replace the link given above with one of the following, or combine the parameters in the way that you want. */
$link='https://'.$subdomain.'.amocrm.com/api/v2/incoming_leads?api_key='.$api_key.'&login='.$login.'&page_size=15';
/* We need to initiate a request to the server. We use the cURL library (supplied as part of PHP). More about work with this library you can read in the manual. */
$curl=curl_init(); #Save the cURL session descriptor
#Set the necessary parameters for the cURL session
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_USERAGENT,'amoCRM-API-client/1.0');
curl_setopt($curl,CURLOPT_HTTPHEADER,['Accept: application/json']);
curl_setopt($curl,CURLOPT_URL,$link);
curl_setopt($curl,CURLOPT_HEADER,false);
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,0);
$out=curl_exec($curl); #Initiate a request to the API and save the response to a variable
$code=curl_getinfo($curl,CURLINFO_HTTP_CODE);
curl_close($curl);
/* Now we can process the response received from the server. This is an example. You can process the data in your own way. */
$code=(int)$code;
$errors=array(
301=>'Moved permanently',
400=>'Bad request',
401=>'Unauthorized',
403=>'Forbidden',
404=>'Not found',
500=>'Internal server error',
502=>'Bad gateway',
503=>'Service unavailable'
);
try
{
#If the response code is not 200 or 204, we return an error message
if($code!=200 && $code!=204)
throw new Exception(isset($errors[$code]) ? $errors[$code] : 'Undescribed error',$code);
}
catch(Exception $E)
{
die('Error: '.$E->getMessage().PHP_EOL.'Error code: '.$E->getCode());
}
Summary information on incoming requests
Method for obtaining aggregated information about incoming requests with the possibility of filtering by date.
Method URL
GET / api / v2 / incoming_leads / summary
Query Parameters
Parameter | Type | Description |
---|---|---|
data/filter/date/from | timestamp | Start date |
data/filter/date/to | timestamp | End Date |
Response parameters
Parameter | Type | Description |
---|---|---|
sip | int | Number of unsorted calls received through incoming calls |
forms | int | Number of unsorted requests received via web forms |
int | Number of unsorted requests received via mail | |
chat | int | Number of unsorted requests received via chat rooms |
total | int | Total number of unsorted requests |
avg_time | timestamp | Average request parsing time in seconds |
>accepted | int | Total number of received requests |
_links | array | Array containing information about the request |
_links/self | array | An array containing information about the current request |
_links/self/href | string | Relative URL of the current request |
_links/self/method | string | Method of the current request |
Response Headers contains the following headers:
-
Content-Type:application/hal+json
-
Runtime-Timestamp: 1508320306
Response example
{
sip: 34,
mail: 43,
form: 33,
chat: 0,
total: 110,
avg_time: 1204101653,
accepted: 45,
_links: {
self: {
href: "/api/v2/incoming_leads/summary?login=example@example.com&api_key=24dbfd65b23ff2ea13a988893be1da61",
method: "get"
}
}
}
Example integration:
$subdomain='test'; #Our account is a subdomain
#Generate a link for the request
$link='https://'.$subdomain.'.amocrm.com/api/v2/incoming_leads/summary/';
/* Note that you can pass other parameters in the reference that affect the output (see documentation).
Therefore, we can replace the link given above with one of the following, or combine the parameters in the way that you want. */
$link='https://'.$subdomain.'.amocrm.com/api/v2/incoming_leads/summary?api_key='.$api_key.'&login='.$login;
/* We need to initiate a request to the server. We use the cURL library (supplied as part of PHP). More about work with this library you can read in the manual. */
$curl=curl_init(); #Save the cURL session descriptor
#Set the necessary parameters for the cURL session
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_USERAGENT,'amoCRM-API-client/1.0');
curl_setopt($curl,CURLOPT_HTTPHEADER,['Accept: application/json']);
curl_setopt($curl,CURLOPT_URL,$link);
curl_setopt($curl,CURLOPT_HEADER,false);
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,0);
$out=curl_exec($curl); #Initiate a request to the API and save the response to a variable
$code=curl_getinfo($curl,CURLINFO_HTTP_CODE);
curl_close($curl);
/* Now we can process the response received from the server. This is an example. You can process the data in your own way. */
$code=(int)$code;
$errors=array(
301=>'Moved permanently',
400=>'Bad request',
401=>'Unauthorized',
403=>'Forbidden',
404=>'Not found',
500=>'Internal server error',
502=>'Bad gateway',
503=>'Service unavailable'
);
try
{
#If the response code is not 200 or 204, we return an error message
if($code!=200 && $code!=204)
throw new Exception(isset($errors[$code]) ? $errors[$code] : 'Undescribed error',$code);
}
catch(Exception $E)
{
die('Error: '.$E->getMessage().PHP_EOL.'Error code: '.$E->getCode());
}