Get the list of leads crm.lead.list
Scope:
crmWho can execute the method: user with read access permission for leads
Method Development Stopped
The method crm.lead.list continues to function, but there is a more relevant alternative crm.item.list.
The method crm.lead.list returns a list of leads based on the filter. It is an implementation of the list method for leads.
Method Parameters
Required parameters are marked with *
|
Name |
Description |
|
select |
The array contains a list of fields to select (see lead fields crm-lead-fields). When selecting, use masks:
There are no masks for selecting multiple fields. To select multiple fields, specify the required ones in the selection list ("PHONE", "EMAIL", etc.). |
|
filter |
An object for filtering the selected leads in the format Possible values for The key can have an additional prefix that clarifies the behavior of the filter. Possible prefix values:
|
|
order
|
|
|
start |
This parameter is used to control pagination. The page size of results is always static: 50 records. To select the second page of results, you need to pass the value The formula for calculating the
|
Also, see the description of list methods.
Code Examples
How to Use Examples in Documentation
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"select":["*","UF_*"],"start":50,"filter":{"=OPPORTUNITY":15000},"order":{"STATUS_ID":"ASC"}}' \
https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/crm.lead.list
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"select":["*","UF_*"],"start":50,"filter":{"=OPPORTUNITY":15000},"order":{"STATUS_ID":"ASC"},"auth":"**put_access_token_here**"}' \
https://**put_your_bitrix24_address**/rest/crm.lead.list
// callListMethod: Retrieves all data at once. Use only for small selections (< 1000 items) due to high memory usage.
try {
const response = await $b24.callListMethod(
'crm.lead.list',
{
select: ['*', 'UF_*'],
filter: {
'=OPPORTUNITY': 15000,
},
order: {
STATUS_ID: 'ASC',
},
},
(progress) => { console.log('Progress:', progress) }
)
const items = response.getData() || []
for (const entity of items) { console.log('Entity:', entity) }
} catch (error) {
console.error('Request failed', error)
}
// fetchListMethod: Retrieves data in parts using an iterator. Use it for large data volumes to optimize memory usage.
try {
const generator = $b24.fetchListMethod('crm.lead.list', {
select: ['*', 'UF_*'],
filter: {
'=OPPORTUNITY': 15000,
},
order: {
STATUS_ID: 'ASC',
},
}, 'ID')
for await (const page of generator) {
for (const entity of page) { console.log('Entity:', entity) }
}
} catch (error) {
console.error('Request failed', error)
}
// callMethod: Manually controls pagination through the start parameter. Use it for precise control of request batches. For large datasets, it is less efficient than fetchListMethod.
try {
const response = await $b24.callMethod('crm.lead.list', {
select: ['*', 'UF_*'],
filter: {
'=OPPORTUNITY': 15000,
},
order: {
STATUS_ID: 'ASC',
},
}, 50)
const result = response.getData().result || []
for (const entity of result) { console.log('Entity:', entity) }
} catch (error) {
console.error('Request failed', error)
}
try {
$order = [];
$filter = []; // Define your filter criteria here
$select = [
'ID', 'TITLE', 'HONORIFIC', 'NAME', 'SECOND_NAME', 'LAST_NAME',
'BIRTHDATE', 'COMPANY_TITLE', 'SOURCE_ID', 'SOURCE_DESCRIPTION',
'STATUS_ID', 'STATUS_DESCRIPTION', 'STATUS_SEMANTIC_ID', 'POST',
'ADDRESS', 'ADDRESS_2', 'ADDRESS_CITY', 'ADDRESS_POSTAL_CODE',
'ADDRESS_REGION', 'ADDRESS_PROVINCE', 'ADDRESS_COUNTRY',
'ADDRESS_COUNTRY_CODE', 'ADDRESS_LOC_ADDR_ID', 'CURRENCY_ID',
'OPPORTUNITY', 'IS_MANUAL_OPPORTUNITY', 'OPENED', 'COMMENTS',
'HAS_PHONE', 'HAS_EMAIL', 'HAS_IMOL', 'ASSIGNED_BY_ID',
'CREATED_BY_ID', 'MODIFY_BY_ID', 'MOVED_BY_ID', 'DATE_CREATE',
'DATE_MODIFY', 'MOVED_TIME', 'COMPANY_ID', 'CONTACT_ID',
'CONTACT_IDS', 'IS_RETURN_CUSTOMER', 'DATE_CLOSED',
'ORIGINATOR_ID', 'ORIGIN_ID', 'UTM_SOURCE', 'UTM_MEDIUM',
'UTM_CAMPAIGN', 'UTM_CONTENT', 'UTM_TERM', 'PHONE', 'EMAIL',
'WEB', 'IM', 'LINK'
];
$startItem = 0;
$leadsResult = $serviceBuilder->getCRMScope()->lead()->list($order, $filter, $select, $startItem);
foreach ($leadsResult->getLeads() as $lead) {
print("ID: {$lead->ID}, TITLE: {$lead->TITLE}, NAME: {$lead->NAME}, BIRTHDATE: " .
($lead->BIRTHDATE ? $lead->BIRTHDATE->format(DATE_ATOM) : 'N/A') . "\n");
}
} catch (Throwable $e) {
print("Error: " . $e->getMessage());
}
BX24.callMethod(
'crm.lead.list',
{
select: ['*', 'UF_*'],
start: 50,
filter: {
'=OPPORTUNITY': 15000,
},
order: {
STATUS_ID: 'ASC',
},
},
(result) => {
if(result.error())
{
console.error(result.error());
return;
}
console.info(result.data());
}
);
require_once('crest.php');
$result = CRest::call(
'crm.lead.list',
[
'select' => ['*', 'UF_*'],
'start' => 50,
'filter' => [
'=OPPORTUNITY' => 15000,
],
'order' => [
'STATUS_ID' => 'ASC',
],
]
);
echo '<PRE>';
print_r($result);
echo '</PRE>';
Some Practical Examples
BX24.callMethod(
"crm.lead.list",
{
order: { "STATUS_ID": "ASC" },
filter: { ">OPPORTUNITY": 0, "!STATUS_ID": "CONVERTED" },
select: [ "ID", "TITLE", "STATUS_ID", "OPPORTUNITY", "CURRENCY_ID" ],
},
(result) => {
if(result.error())
{
console.error(result.error());
}
else
{
console.dir(result.data());
if (result.more())
{
result.next();
}
}
}
);
BX24.callMethod(
"crm.lead.list",
{
filter: { "PHONE": "555888" },
select: [ "ID", "TITLE" ]
},
(result) => {
if(result.error())
{
console.error(result.error());
}
else
{
console.dir(result.data());
if (result.more())
{
result.next();
}
}
}
);
$result = CRest::call(
'crm.lead.list',
[
'filter' => [
'>DATE_CREATE' => '2023-10-01T00:00:00',
'<DATE_CREATE' => '2023-10-31T23:59:59',
],
'select' => [
'ID',
'DATE_CREATE',
],
]
);
Response Handling
HTTP Status: 200
{
"result": [
{
"ID": "5",
"TITLE": "Lead 1",
"HONORIFIC": null,
"NAME": "Erasmus",
"SECOND_NAME": null,
"LAST_NAME": "Golden of Ireland",
"COMPANY_TITLE": null,
"COMPANY_ID": "0",
"CONTACT_ID": "2069",
"IS_RETURN_CUSTOMER": "N",
"BIRTHDATE": "",
"SOURCE_ID": "CALL",
"SOURCE_DESCRIPTION": null,
"STATUS_ID": "CONVERTED",
"STATUS_DESCRIPTION": null,
"POST": null,
"COMMENTS": null,
"CURRENCY_ID": "USD",
"OPPORTUNITY": "15000.00",
"IS_MANUAL_OPPORTUNITY": "Y",
"HAS_PHONE": "Y",
"HAS_EMAIL": "Y",
"HAS_IMOL": "N",
"ASSIGNED_BY_ID": "1",
"CREATED_BY_ID": "1",
"MODIFY_BY_ID": "1",
"DATE_CREATE": "2021-05-31T15:10:16+02:00",
"DATE_MODIFY": "2021-11-26T18:56:13+02:00",
"DATE_CLOSED": "2021-07-16T16:43:44+02:00",
"STATUS_SEMANTIC_ID": "S",
"OPENED": "Y",
"ORIGINATOR_ID": null,
"ORIGIN_ID": null,
"MOVED_BY_ID": "1",
"MOVED_TIME": "2021-07-16T16:43:44+02:00",
"ADDRESS": "7677 Hollow Ridge Alley",
"ADDRESS_2": null,
"ADDRESS_CITY": null,
"ADDRESS_POSTAL_CODE": null,
"ADDRESS_REGION": null,
"ADDRESS_PROVINCE": null,
"ADDRESS_COUNTRY": "Indonesia",
"ADDRESS_COUNTRY_CODE": null,
"ADDRESS_LOC_ADDR_ID": "1",
"UTM_SOURCE": null,
"UTM_MEDIUM": null,
"UTM_CAMPAIGN": null,
"UTM_CONTENT": null,
"UTM_TERM": null,
"LAST_ACTIVITY_BY": "1",
"LAST_ACTIVITY_TIME": "2021-05-31T15:10:16+02:00",
"UF_CRM_1704817278": null,
"UF_CRM_1706782596092": null,
"UF_CRM_1708952993785": false
},
{
"ID": "6",
"TITLE": "Lead 2",
"HONORIFIC": null,
"NAME": "Ignacius",
"SECOND_NAME": null,
"LAST_NAME": "Slayny",
"COMPANY_TITLE": null,
"COMPANY_ID": "0",
"CONTACT_ID": "2070",
"IS_RETURN_CUSTOMER": "N",
"BIRTHDATE": "",
"SOURCE_ID": "CALL",
"SOURCE_DESCRIPTION": null,
"STATUS_ID": "CONVERTED",
"STATUS_DESCRIPTION": null,
"POST": null,
"COMMENTS": null,
"CURRENCY_ID": "USD",
"OPPORTUNITY": "15000.00",
"IS_MANUAL_OPPORTUNITY": "Y",
"HAS_PHONE": "Y",
"HAS_EMAIL": "Y",
"HAS_IMOL": "N",
"ASSIGNED_BY_ID": "1",
"CREATED_BY_ID": "1",
"MODIFY_BY_ID": "1",
"DATE_CREATE": "2021-05-31T15:10:16+02:00",
"DATE_MODIFY": "2021-11-26T18:56:13+02:00",
"DATE_CLOSED": "2021-07-16T16:43:47+02:00",
"STATUS_SEMANTIC_ID": "S",
"OPENED": "Y",
"ORIGINATOR_ID": null,
"ORIGIN_ID": null,
"MOVED_BY_ID": "1",
"MOVED_TIME": "2021-07-16T16:43:47+02:00",
"ADDRESS": "35 Mosinee Street",
"ADDRESS_2": null,
"ADDRESS_CITY": null,
"ADDRESS_POSTAL_CODE": null,
"ADDRESS_REGION": null,
"ADDRESS_PROVINCE": null,
"ADDRESS_COUNTRY": "Japan",
"ADDRESS_COUNTRY_CODE": null,
"ADDRESS_LOC_ADDR_ID": "2",
"UTM_SOURCE": null,
"UTM_MEDIUM": null,
"UTM_CAMPAIGN": null,
"UTM_CONTENT": null,
"UTM_TERM": null,
"LAST_ACTIVITY_BY": "1",
"LAST_ACTIVITY_TIME": "2021-05-31T15:10:16+02:00",
"UF_CRM_1704817278": null,
"UF_CRM_1706782596092": null,
"UF_CRM_1708952993785": true
},
48 more leads with similar structure
],
"next": 50,
"total": 654,
"time": {
"start": 1718292234.554781,
"finish": 1718292234.657739,
"duration": 0.10295796394348145,
"processing": 0.05574321746826172,
"date_start": "2024-06-13T18:23:54+02:00",
"date_finish": "2024-06-13T18:23:54+02:00",
"operating": 0
}
}
Returned Data
|
Name |
Description |
|
result |
The root element of the response. Contains an array of objects that hold information about the fields of deals. It should be noted that the structure of the fields may change due to the For information about the structure of a lead, see the method |
|
total |
The total number of found items |
|
next |
Contains the value to be passed in the next request in the The |
|
time |
Information about the execution time of the request |
Error Handling
HTTP Status: 40x, 50x Error
{
"error": "",
"error_description": "Access denied."
}
|
Name |
Description |
|
error |
String error code. It may consist of digits, Latin letters, and underscores |
|
error_description |
Textual description of the error. The description is not intended to be shown to the end user in its raw form |
Possible Errors
|
Error Text |
Description |
|
|
The user does not have permission to read leads |
Statuses and System Error Codes
HTTP Status: 20x, 40x, 50x
The errors described below may occur when calling any method.
|
Status |
Code |
Description |
|
|
|
An internal server error has occurred, please contact the server administrator or Bitrix24 technical support |
|
|
|
An internal server error has occurred, please contact the server administrator or Bitrix24 technical support |
|
|
|
The request intensity limit has been exceeded |
|
|
|
The current method is not allowed to be called using batch |
|
|
|
The maximum length of parameters passed to the batch method has been exceeded |
|
|
|
Invalid access token or webhook code |
|
|
|
The methods must be called using the HTTPS protocol |
|
|
|
The REST API is blocked due to overload. This is a manual individual block, to remove it you need to contact Bitrix24 technical support |
|
|
|
The REST API is available only on commercial plans |
|
|
|
The user whose access token or webhook was used to call the method lacks permissions |
|
|
|
The manifest is not available |
|
|
|
The request requires higher privileges than those provided by the webhook token |
|
|
|
The provided access token has expired |
|
|
|
The user does not have access to the application. This means that the application is installed, but the account administrator has allowed access to this application only for specific users |
|
|
|
The public part of the site is closed. To open the public part of the site on an on-premise installation, disable the option "Temporary closure of the public part of the site". Path to the setting: Desktop > Settings > Product Settings > Module Settings > Main Module > Temporary closure of the public part of the site |