[
{
"to_entity_id": <ID ТОВАРА>,
"to_entity_type": "catalog_elements",
"metadata": {
"catalog_id": <ID КАТАЛОГА>,
"quantity": <КОЛИЧЕСТВО>
}
}
]
$.ajax({
url: `/api/v4/leads/${lead_id}/link`,
method: 'POST',
contentType: 'applcation/json',
data: JSON.stringify([
{
"to_entity_id": <ID ТОВАРА>,
"to_entity_type": "catalog_elements",
"metadata": {
"catalog_id": <ID КАТАЛОГА>,
"quantity": <КОЛИЧЕСТВО>
}
])
})
PATCH /api/v4/{entity_type}/{entity_id}
[[{"name":"\u041a\u043e\u043d\u0442\u0430\u043a\u04421","custom_fields_values":[{"field_id":764147,"values":[{"value":"\u0410\u0440\u0430\u0431\u0438\u043a\u0430","enum_id":"1011877"}]}],"id":"22130181"}]]
должно быть {"name":"\u041a\u043e\u043d\u0442\u0430\u043a\u04421","custom_fields_values":[{"field_id":764147,"values":[{"value":"\u0410\u0440\u0430\u0431\u0438\u043a\u0430","enum_id":"1011877"}]}]}
<?php
use AmoCRM\Client;
require __DIR__ . '/vendor/autoload.php';
if (isset($_POST['phone'])) {
try {
$subdomain = 'ДОМЕН';
$login = 'ЛОГИН';
$apikey = 'КЛЮЧ';
$amo = new Client($subdomain, $login, $apikey);
$unsorted = $amo->unsorted;
$unsorted['source'] = 'my-site';
$unsorted['source_uid'] = 'uid_source';
$unsorted['source_data'] = [
'data' => [],
'form_id' => 'form_id',
'form_type' => 1,
'date' => time(),
'from' => 'my-site-url',
'form_name' => 'my-site-name',
'origin' => [
'ip' => '127.0.0.1',
'datetime' => '',
'referer' => '',
],
];
$lead = $amo->lead;
$lead['name'] = $_POST['product_name'];
$unsorted->addDataLead($lead);
$contact = $amo->contact;
$contact['name'] = isset($_POST['name']) ? $_POST['name'] : 'Не указано';
$contact->addCustomField(
224429,
[
[$_POST['phone'], 'MOB'],
]
);
$contact->addCustomField(
224431,
[
[$_POST['email'], 'PRIV'],
]
);
$unsorted->addDataContact($contact);
$unsortedId = $unsorted->apiAddForms();
} catch (\AmoCRM\Exception $e) {
var_dump(json_decode($e->getMessage(), 1));
printf('Error (%d): %s' . PHP_EOL, $e->getCode(), $e->getMessage());
}
}
?>
<form method="post" action="call.php">
<div class="form_group">
<p class="input-txt">Имя: <span>*</span></p>
<input type="text" id="name" class="form__input" name="name" required="required">
</div>
<div class="form_group">
<p class="input-txt">Электронная почта: <span>(не обязательно)</span></p>
<input type="email" id="email" class="form__input" name="email" required="required">
</div>
<div class="form_group">
<p class="input-txt">Телефон: <span>*</span></p>
<input type="text" id="phone" class="form__input phone-mask" name="phone" required="required">
</div>
<div>
</div>
<button type="submit" class="btn form-btn">СВЯЗАТЬСЯ</button>
</form>
<?php
$data = $_POST['leads']['update'][0];
$data['custom_fields'] = isset($data['custom_fields']) ? $data['custom_fields'] : array();
$id = $data['id'];
$lead_cf = array();
foreach ($data['custom_fields'] as $custom_field) {
$lead_cf[$custom_field['id']] = $custom_field;
}
if (!isset($lead_cf[514667]) || !isset($lead_cf[514669])) {
exit();
}
$predoplata = intval($lead_cf[514667]['values'][0]['value']);
$postoplata = intval($lead_cf[514669]['values'][0]['value']);
if ($predoplata === 0 || $postoplata === 0) {
exit();
}
$sale = $postoplata + $predoplata;
$prev_sale = isset($lead_cf[514689]) ? intval($lead_cf[514689]['values'][0]['value']) : null;
if ($prev_sale !== $sale) {
$lead = array(
'update' => array(
array(
'id' => $id,
'updated_at' => time(),
'custom_fields' => array(
array(
'id' => 514689,
'values' => array(
array(
'value' => $sale
),
),
),
),
),
),
);
// TODO: SEND TO AMO
}
GET https://<subdomain>.amocrm.ru/api/v3/contacts
/api/v3/contacts?filter[266363]=test@test.test