Call Object

The “calls” method sends call data to contact or company cards. Because events do not have an assigned user or date, they are displayed alongside tasks. If the call contains a call recording, then the audio player interface will be available in the card.

The method adds new calls one by one or batchwise to the processing queue for subsequent movement to the “events” table. After adding calls using “calls/add”, recordings appear in the processing queue. If the contact’s phone number matches the specified parameters, then a “call” note will be created in the contact card. If a contact was not found in 18 hours, then the call will be deleted.

It is important to note that in order to add a call using the “calls/add” method, you need to have a unique service key. To get this key, you should upload your virtual PBX widget (the test widget is acceptable) into an account and contact our technical support.

You can add calls to various amoCRM accounts, provided that users:

  • Install the widget
  • Match the unique key to the unique key in the original version

Resource URL

POST /api/calls/add/

GET parameters

Parameter Type Description
code

require
string Unique service identifier.
key

require
string (numeral) Service key, which you can get by writing to amoCRM tech support.

Parameters

Parameter Type Description
account_id

require
string (numeral) Identification number where the call took place.
uuid

require
string Unique call identifier. It is sent by you.
caller

require
string (numeral) Outgoing caller’s number. It is considered the user account number. The list of users should be stored in the widget settings in the ‘phones’ key in the’ users’ type field in the format {user_id: phone} or in the ‘phones_lp’ key in the ‘users_lp’ type field. Then the phone number you search for will be the value in the login key of the array element ‘phones_lp’.
to

require
string (numeral) Incoming caller’s number. It is considered the user account number. The list of users should be stored in the widget settings in the ‘phones’ key in the’ users’ type field in the format {user_id: phone} or in the ‘phones_lp’ key in the ‘users_lp’ type field. Then the phone number you search for will be the value in the login key of the array element ‘phones_lp’.
date

require
timestamp Call date.
type

require
string Call type (inbound – incoming, outbound – outgoing).
billsec

require
int Call duration in seconds.
link string File link with call recording.

Here is an example of add call request.

Integration example

 array(
        'uuid' => '394427aaf821879e29efbc4eb98ef13271514',
        'caller' => 117,
        'to' => '14155237743',
        'date' => 1414654739,
        'billsec' => 98,
        'type' => 'inbound',
        'link' => 'http:///* link of recording */.mp3',
        'account_id' => 1111111
    ),
    1 => array(
        'uuid' => 'b7095fb33b368c7103626d3943d9e61c14697',
        'caller' => 280,
        'to' => '12566079249',
        'date' => 1414653676,
        'billsec' => 57,
        'type' => 'outbound',
        'link' => 'http:///* link of recording */.mp3',
        'account_id' => 1111111
    ),
);
$code = 'my_service_name'; # Your widget code in amoCRM
$key = '601eb8fab9707d8009dba552f2d411a3'; # a key, which you get in tech support
$account_id = 39099; # Account identification number where calls are added
#Form a request link
$link = 'https://sip.amocrm.com/api/calls/add/?code=' . $code . '&key=' . $key . '&account_id=' . $account_id;
#Alternatively, you can send the request link without the account_id by sending it in an array with the call data
$curl = curl_init(); #Save the descriptor of the cURL session
#Set the necessary options for the cURL session
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_USERAGENT, 'amoCRM-API-client/1.0');
curl_setopt($curl, CURLOPT_HEADER, FALSE);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_URL, $link);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($calls));
$out = curl_exec($curl); #Initiate an API request and save the output in a variable
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$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 equal 200 or 204 - return the error message
    if ($code != 200 && $code != 204)
        throw new Exception(isset($errors[$code]) ? $errors[$code] : 'Undescribed error', (int)$code);
} catch (Exception $E) {
    die('Error: ' . $E->getMessage() . PHP_EOL . 'Error code: ' . $E->getCode());
}
/*
 Because we receive data in JSON format,
 we need to translate the response into a format that PHP recognizes to get readable data
 */
$response = json_decode($out, TRUE);
if (count($response['response']['calls']['add']['success']) > 0) {
    $output .= 'Successfully added calls:' . PHP_EOL;
    foreach ($response['response']['calls']['add']['success'] as $v) {
        $output .= $v . PHP_EOL;
    }
}
if (count($response['response']['calls']['add']['errors']) > 0) {
    $output .= 'Errors:' . PHP_EOL;
    foreach ($response['response']['calls']['add']['errors'] as $uuid => $reasons) {
        $output .= $uuid . ' - ' . implode(', ', $reasons) . PHP_EOL;
    }
}