...
$link = 'https://' . $domain . '.amocrm.ru/api/v2/leads?limit_rows=50&limit_offset=' . $offset;
$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_HEADER, false);
curl_setopt($curl, CURLOPT_COOKIEFILE, __DIR__ . '/cookie.txt');
curl_setopt($curl, CURLOPT_COOKIEJAR, __DIR__ . '/cookie.txt');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
$outLeads = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
$response = json_decode($outLeads, true);
$response = $response['_embedded']['items'];
$actualRows = count($response);
$leads = [];
$leads['update'] = [];
foreach ($response as $item) {
...
<?php
$user = array(
'USER_LOGIN' => '<USER LOGIN>',
'USER_HASH' => '<USER HASH>'
);
$subdomain = '<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, __DIR__ . '/cookie.txt');
curl_setopt($curl, CURLOPT_COOKIEJAR, __DIR__ . '/cookie.txt');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
$out = json_decode(curl_exec($curl), 1);
curl_close($curl);
$leads = [];
$link = 'https://' . $subdomain . '.amocrm.ru/api/v3/leads?limit=1000&filter[<FIELDS ID>]=';
do {
$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_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_COOKIEFILE, __DIR__ . '/cookie.txt');
curl_setopt($curl, CURLOPT_COOKIEJAR, __DIR__ . '/cookie.txt');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
$out = json_decode(curl_exec($curl), 1);
curl_close($curl); #Завершаем сеанс cURL
$leads = array_merge($out['_embedded']['leads']);
$link = $out['_links']['next']['href'];
} while (isset($out['_links']['next']));
$update_leads = [];
foreach ($leads as $lead) {
$update_leads[] = [
'id' => $lead['id'],
'updated_at' => time(),
'custom_fields' => [
[
'id' => <FIELDS ID>,
'values' => [
[
'value' => <FIELDS VALUE>
]
]
]
]
];
}
echo '<pre>';
var_dump($update_leads);
echo '</pre>';
<?php
$user = array(
'USER_LOGIN' => '<USER LOGIN>',
'USER_HASH' => '<USER HASH>'
);
$subdomain = '<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, __DIR__ . '/cookie.txt');
curl_setopt($curl, CURLOPT_COOKIEJAR, __DIR__ . '/cookie.txt');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
$out = json_decode(curl_exec($curl), 1);
curl_close($curl);
$leads = [];
$link = 'https://' . $subdomain . '.amocrm.ru/api/v3/leads?limit=1000&filter[<FIELDS ID>]=';
do {
$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_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_COOKIEFILE, __DIR__ . '/cookie.txt');
curl_setopt($curl, CURLOPT_COOKIEJAR, __DIR__ . '/cookie.txt');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
$out = json_decode(curl_exec($curl), 1);
curl_close($curl); #Завершаем сеанс cURL
$leads = array_merge($out['_embedded']['leads']);
$link = $out['_links']['next']['href'];
} while (isset($out['_links']['next']));
$update_leads = [];
foreach ($leads as $lead) {
$update_leads[] = [
'id' => $lead['id'],
'updated_at' => time(),
'custom_fields' => [
[
'id' => <FIELDS ID>,
'values' => [
[
'value' => <FIELDS VALUE>
]
]
]
]
];
}
echo '<pre>';
var_dump($update_leads);
echo '</pre>';
$link = 'https://' . $subdomain . '.amocrm.ru/api/v3/leads?limit=10000&filter[504091]=';
$link = 'https://' . $subdomain . '.amocrm.ru/api/v3/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($update_leads));
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_COOKIEFILE, __DIR__ . '/cookie.txt');
curl_setopt($curl, CURLOPT_COOKIEJAR, __DIR__ . '/cookie.txt');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
$out = json_decode(curl_exec($curl), 1);
curl_close($curl);
$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(['update' => $update_leads]));
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_COOKIEFILE, __DIR__ . '/cookie.txt');
curl_setopt($curl, CURLOPT_COOKIEJAR, __DIR__ . '/cookie.txt');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
$out = json_decode(curl_exec($curl), 1);
curl_close($curl);
$link = 'https://' . $subdomain . '.amocrm.ru/api/v3/leads?limit=10000&filter[504091]=&filter[123456]=';
$update_leads = [];
foreach ($leads as $lead) {
$update_leads[] = [
'id' => $lead['id'],
'updated_at' => time(),
'custom_fields' => [
[
'id' => 504091,
'values' => [
[
'value' => <FIELDS VALUE>
]
]
],
[
'id' => 123456,
'values' => [
[
'value' => 'TEST'
]
]
]
]
];
}
'id' => 123456,
'values' => [
[
'value' => generateLink($custom_fields)
]
]
$link = 'https://' . $subdomain . '.amocrm.ru/api/v3/leads?limit=1000&filter[123456]=';
$link = 'https://' . $subdomain . '.amocrm.ru/api/v3/leads?limit=1000&filter[123456]=&fields=1234567,sale,654321';