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

  1. $calls['request']['add'] = array(
  2.     0 => array (
  3.         'uuid' => '394427aaf821879e29efbc4eb98ef13271514',
  4.         'caller' => 117,
  5.         'to' => '14155237743',
  6.         'date' => 1414654739,
  7.         'billsec' => 98,
  8.         'type' => 'inbound',
  9.     'link' => 'http:///* link of recording */.mp3',
  10.         'account_id'=>1111111
  11.     ),
  12.     1 => array (
  13.         'uuid' => 'b7095fb33b368c7103626d3943d9e61c14697',
  14.         'caller' => 280,
  15.         'to' => '12566079249',
  16.         'date' => 1414653676,
  17.         'billsec' => 57,
  18.         'type' => 'outbound',
  19.         'link' => 'http:///* link of recording */.mp3',
  20.         'account_id'=>1111111
  21.     ),
  22. );
  23. $code = 'my_service_name'; # Your widget code in amoCRM
  24. $key = '601eb8fab9707d8009dba552f2d411a3'; # a key, which you get in tech support
  25. $account_id = 39099; # Account identification number where calls are added
  26. #Form a request link
  27. $link='https://sip.amocrm.com/api/calls/add/?code=' . $code . '&key=' . $key . '&account_id=' . $account_id;
  28. #Alternatively, you can send the request link without the account_id by sending it in an array with the call data
  29. $curl=curl_init(); #Save the descriptor of the cURL session
  30. #Set the necessary options for the cURL session
  31. curl_setopt($curl,CURLOPT_POST,TRUE);
  32. curl_setopt($curl,CURLOPT_RETURNTRANSFER,TRUE);
  33. curl_setopt($curl,CURLOPT_USERAGENT,'amoCRM-API-client/1.0');
  34. curl_setopt($curl,CURLOPT_HEADER,FALSE);
  35. curl_setopt($curl,CURLOPT_TIMEOUT,30);
  36. curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,0);
  37. curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,0);
  38. curl_setopt($curl,CURLOPT_URL,$link);
  39. curl_setopt($curl,CURLOPT_POSTFIELDS,http_build_query($calls));
  40. $out=curl_exec($curl); #Initiate an API request and save the output in a variable
  41. $code=curl_getinfo($curl,CURLINFO_HTTP_CODE);
  42. $code=(int)$code;
  43. $errors=array(
  44.     301=>'Moved permanently',
  45.     400=>'Bad request',
  46.     401=>'Unauthorized',
  47.     403=>'Forbidden',
  48.     404=>'Not found',
  49.     500=>'Internal server error',
  50.     502=>'Bad gateway',
  51.     503=>'Service unavailable'
  52. );
  53. try
  54. {
  55.     #If the response code is not equal 200 or 204 - return the error message
  56.    if($code!=200 && $code!=204)
  57.         throw new Exception(isset($errors[$code]) ? $errors[$code] : 'Undescribed error',(int)$code);
  58. }
  59. catch(Exception $E)
  60. {
  61.     die('Error: '.$E->getMessage().PHP_EOL.'Error code: '.$E->getCode());
  62. }
  63. /*
  64.  Because we receive data in JSON format,
  65.  we need to translate the response into a format that PHP recognizes to get readable data
  66.  */
  67. $response=json_decode($out,TRUE);
  68. if( count($response['response']['calls']['add']['success']) > 0 ) {
  69.     $output .= 'Successfully added calls:' . PHP_EOL;
  70.     foreach($response['response']['calls']['add']['success'] as $v) {
  71.         $output .= $v . PHP_EOL;
  72.     }
  73. }
  74.  if( count($response['response']['calls']['add']['errors']) > 0 ) {
  75. $output .= 'Errors:' . PHP_EOL;
  76. foreach($response['response']['calls']['add']['errors'] as $uuid => $reasons) {
  77.     $output .= $uuid . ' - ' . implode(', ', $reasons) . PHP_EOL;
  78. }
  79. }