AMOCRM.constant('managers')
[
{
"id": 56440444,
"custom_fields_values": [
{
"field_id": 1961348,
"values": [
{
"value": 13
}
]
},
{
"field_id": 1961338,
"values": [
{
"value": "https://url.ru"
}
]
},
{
"field_id": 1961350,
"values": [
{
"value": 0
}
]
},
{
"field_id": 1961340,
"values": [
{
"value": 16
}
]
},
{
"field_id": 1961342,
"values": [
{
"value": 1
}
]
},
{
"field_id": 1961344,
"values": [
{
"value": 1
}
]
},
{
"field_id": 1961346,
"values": [
{
"value": 16
}
]
},
{
"field_id": 1961352,
"values": [
{
"value": 0
}
]
},
{
"field_id": 1961354,
"values": [
{
"value": 13
}
]
},
{
"field_id": 1961356,
"values": [
{
"value": 13
}
]
},
{
"field_id": 1961358,
"values": [
{
"value": 1639991140
}
]
},
{
"field_id": 1961360,
"values": [
{
"value": 1
}
]
},
{
"field_id": 1961362,
"values": [
{
"value": 1
}
]
},
{
"field_id": 1961364,
"values": [
{
"value": 0
}
]
}
]
},
{
"id": 56487008,
"custom_fields_values": [
{
"field_id": 1961338,
"values": [
{
"value": "https://url.ru"
}
]
},
{
"field_id": 1961340,
"values": [
{
"value": 16
}
]
},
{
"field_id": 1961342,
"values": [
{
"value": 1
}
]
},
{
"field_id": 1961344,
"values": [
{
"value": 1
}
]
},
{
"field_id": 1961346,
"values": [
{
"value": 16
}
]
},
{
"field_id": 1961348,
"values": [
{
"value": 13
}
]
},
{
"field_id": 1961350,
"values": [
{
"value": 0
}
]
},
{
"field_id": 1961352,
"values": [
{
"value": 0
}
]
},
{
"field_id": 1961354,
"values": [
{
"value": 13
}
]
},
{
"field_id": 1961356,
"values": [
{
"value": 13
}
]
},
{
"field_id": 1961358,
"values": [
{
"value": 1639991140
}
]
},
{
"field_id": 1961360,
"values": [
{
"value": 1
}
]
},
{
"field_id": 1961362,
"values": [
{
"value": 1
}
]
},
{
"field_id": 1961364,
"values": [
{
"value": 0
}
]
}
]
},
{
"id": 56487018,
"custom_fields_values": [
{
"field_id": 1961338,
"values": [
{
"value": "https://url.ru"
}
]
},
{
"field_id": 1961340,
"values": [
{
"value": 16
}
]
},
{
"field_id": 1961342,
"values": [
{
"value": 1
}
]
},
{
"field_id": 1961344,
"values": [
{
"value": 1
}
]
},
{
"field_id": 1961346,
"values": [
{
"value": 16
}
]
},
{
"field_id": 1961348,
"values": [
{
"value": 13
}
]
},
{
"field_id": 1961350,
"values": [
{
"value": 0
}
]
},
{
"field_id": 1961352,
"values": [
{
"value": 0
}
]
},
{
"field_id": 1961354,
"values": [
{
"value": 13
}
]
},
{
"field_id": 1961356,
"values": [
{
"value": 13
}
]
},
{
"field_id": 1961358,
"values": [
{
"value": 1639991140
}
]
},
{
"field_id": 1961360,
"values": [
{
"value": 1
}
]
},
{
"field_id": 1961362,
"values": [
{
"value": 1
}
]
},
{
"field_id": 1961364,
"values": [
{
"value": 0
}
]
}
]
}
]
<?php
$subdomain = 'test';
$offset = 0;
$size = 500;
$link = "https://$subdomain.amocrm.ru/api/v2/leads";
$temp = [];
do {
$res = request($link, 'USER_LOGIN', 'USER_HASH', [
'limit_rows' => $size,
'limit_offset' => $offset
]);
$offset += $size;
if ($itsOk = ($res['code'] === 200)) {
$temp[] = $res['response']['_embedded']['items'];
}
} while ($itsOk);
$leads = array_merge([], ...$temp);
$leadsIds = array_column($leads, 'id');
var_dump($leadsIds);
/* Для API-Key */
function request($link, $user_login, $user_hash, $params = [])
{
$params['USER_LOGIN'] = $user_login;
$params['USER_HASH'] = $user_hash;
$tries = 0;
do {
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $link . '?' . http_build_query($params));
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
$out = curl_exec($curl);
$code = (int)curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($code === 429) {
if ($tries++ > 3) {
throw new RuntimeException('Превышено допустимое количество запросов в секунду');
}
sleep(1);
}
} while ($code === 429);
return ['code' => $code, 'response' => json_decode($out, 1)];
}
/* Для OAuth
function request($link, $access_token, $params = [])
{
$tries = 0;
do {
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $link . '?' . http_build_query($params));
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $access_token));
$out = curl_exec($curl);
$code = (int)curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($code === 429) {
if ($tries++ > 3) {
throw new RuntimeException('Превышено допустимое количество запросов в секунду');
}
sleep(1);
}
} while ($code !== 429);
return ['code' => $code, 'response' => json_decode($out, 1)];
}
*/