-
-
Save m4tlch/967bec981c5ae6b8d62f91a6f723dc28 to your computer and use it in GitHub Desktop.
amoCRM unsorted form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ваши данные для авторизации | |
$api_key = ''; | |
$login = ''; | |
$subdomain = ''; | |
// id полей в вашем аккаунте | |
$phone_field_id = ; | |
$phone_type_id = ; | |
// добавляемые данные | |
$phone = '1234567890'; | |
$lead_name = 'Название сделки'; | |
$source = 'mysite.ru'; | |
//////////////////////////////////////// | |
$data['request']['unsorted'] = [ | |
'category' => 'forms', | |
'add' => [[ | |
'source' => $source, | |
'source_uid' => NULL, | |
'data' => [ | |
'leads' => [[ | |
'name' => $lead_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_key=$api_key&login=$login"; | |
$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); | |
echo $code . "<br>" . $out; // вывод на экран | |
// file_put_contents('log.txt', $code . "\n" . $out); // запись в файл |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment