<?php
$api_key = 'ххх';
$login = 'хххх';
$subdomain = 'ххх';
$phone_field_id = 98603;
$phone_type_id = 205485;
$phone = $_POST['phone'];
$forma = $_POST['forma'];
$lead_name = $_POST['name'];
$source = 'Заявка с сайта ххх';
// дальше ничего менять не нужно
$data['request']['unsorted'] = [
'category' => 'forms',
'add' => [[
'source' => $source,
'source_uid' => NULL,
'data' => [
'leads' => [[
'name' => 'Заявка на санобработку',
]],
'contacts' => [[
'name' => $lead_name,
'custom_fields' => [[
'id' => $phone_field_id,
'values' => [[
'enum' => $phone_type_id,
'value' => $phone,
]],
]],
]],
],
'source_data' => [
'data' => [[
'type' => 'multitext',
'id' => $phone_field_id,
'element_type' => '1',
'name' => 'Телефон',
'value' => [$phone]
]],
'form_id' => 1,
'form_type' => 1,
'origin' => ['ip' => '0.0.0.0'],
'date' => time(),
'from' => $source,
],
]],
];
$link = "
https://$subdomain.amocrm.ru/api/unsorted/add/?api...";
$curl = curl_init();
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);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
/*формируем отчет об ошибках*/
$set = json_encode($set);
$log = '';
$log .= "set:\n$set_str\n\n";
$log .= "code:\n$code\n\n";
$log .= "out:\n$out\n\n";
file_put_contents('log.txt', $out);
/*****/
// echo $code . "
" . $out; // вывод на экран
// file_put_contents('log.txt', $code . "\n" . $out); // запись в файл