Добрый вечер, нужна помощь, приходит пустая заявка в amo.
#Параметры для авторизации
$user = array(
'USER_LOGIN' => '#',
'USER_HASH' => '#',
);
$subdomain = '#';
$link = 'https://' . $subdomain . '.amocrm.ru/private/api/auth.php?type=json';
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_USERAGENT, 'amoCRM-API-client/1.0');
curl_setopt($curl, CURLOPT_URL, $link);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($user));
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_COOKIEFILE, dirname (__FILE__) . '/cookie.txt');
curl_setopt($curl, CURLOPT_COOKIEJAR, dirname (__FILE__) . '/cookie.txt');
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);
$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 ($code != 200 && $code != 204) {
throw new Exception(isset($errors[$code]) ? $errors[$code] : 'Undescribed error', $code);
}
} catch (Exception $E) {
die('Ошибка: ' . $E->getMessage() . PHP_EOL . 'Код ошибки: ' . $E->getCode());
}
# Добавление сделки
$leads['add'] = array(
array(
'name' => $form,
'cont_name' => $name,
'custom_fields'=> [
[
'id' => 352382,
'values' => [
[
'value'=> $phone,
'enum'=>'MOB'
]
]
],
[
'id' => 391663,
'values' => [
[
'value'=> $utm_source,
]
]
],
[
'id' => 391665,
'values' => [
[
'value'=> $utm_medium,
]
]
],
[
'id' => 391667,
'values' => [
[
'value'=> $utm_campaign,
]
]
],
[
'id' => 391669,
'values' => [
[
'value'=> $utm_content,
]
]
],
[
'id' => 391671,
'values' => [
[
'value'=> $utm_term,
]
]
]
]
),
);
$link = 'https://' . $subdomain . '.amocrm.ru/api/v2/leads';
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_USERAGENT, 'amoCRM-API-client/1.0');
curl_setopt($curl, CURLOPT_URL, $link);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($leads));
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_COOKIEFILE, dirname(__FILE__) . '/cookie.txt');
curl_setopt($curl, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/cookie.txt');
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);
$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 ($code != 200 && $code != 204) {
throw new Exception(isset($errors[$code]) ? $errors[$code] : 'Undescribed error', $code);
}
} catch (Exception $E) {
die('Ошибка: ' . $E->getMessage() . PHP_EOL . 'Код ошибки: ' . $E->getCode());
}
Print_r выдает
Array ( [0] => Array ( [cont_name] => 312312 [custom_fields] => Array ( [0] => Array ( [id] => 352382 [values] => Array ( [0] => Array ( [value] => 6546465 [enum] => MOB ) ) ) [1] => Array ( [id] => 391663 [values] => Array ( [0] => Array ( [value] => ) ) ) [2] => Array ( [id] => 391665 [values] => Array ( [0] => Array ( [value] => ) ) ) [3] => Array ( [id] => 391667 [values] => Array ( [0] => Array ( [value] => ) ) ) [4] => Array ( [id] => 391669 [values] => Array ( [0] => Array ( [value] => ) ) ) [5] => Array ( [id] => 391671 [values] => Array ( [0] => Array ( [value] => ) ) ) ) ) )