Get the list of leads crm.lead.list

Scope: crm

Who 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
type

Description

select
array

The array contains a list of fields to select (see lead fields crm-lead-fields).

When selecting, use masks:

  • "*" - to select all fields (excluding custom and multiple fields)
  • "UF_*" - to select all custom fields (excluding multiple fields)

There are no masks for selecting multiple fields. To select multiple fields, specify the required ones in the selection list ("PHONE", "EMAIL", etc.).
There is no option to add a logical OR condition to the filter if you need to select by several different fields.

filter
object

An object for filtering the selected leads in the format {"field_1": "value_1", ... "field_N": "value_N"}.

Possible values for field correspond to lead fields crm-lead-fields.

The key can have an additional prefix that clarifies the behavior of the filter. Possible prefix values:

  • >= — greater than or equal to

  • > — greater than

  • <= — less than or equal to

  • < — less than

  • @ — IN (an array is passed as the value)

  • !@ — NOT IN (an array is passed as the value)

  • % — LIKE, substring search. The "%" symbol in the filter value does not need to be passed. The search looks for the substring in any position of the string.

  • =% — LIKE, substring search. The "%" symbol needs to be passed in the value. Examples:

    • "mol%" — searching for values starting with "mol"
    • "%mol" — searching for values ending with "mol"
    • "%mol%" — searching for values where "mol" can be in any position
  • %= — LIKE (see description above)

  • !% — NOT LIKE, substring search. The "%" symbol in the filter value does not need to be passed. The search goes from both sides.

  • =% — NOT LIKE, substring search. The "%" symbol needs to be passed in the value. Examples:

    • "mol%" — searching for values not starting with "mol"
    • "%mol" — searching for values not ending with "mol"
    • "%mol%" — searching for values where the substring "mol" is not in any position
  • !%= — NOT LIKE (see description above)

  • = — equals, exact match (used by default)

  • != - not equal

  • ! — not equal

order
Possible values for order:

  • asc — in ascending order
  • desc — in descending order

start
integer

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 50. To select the third page of results — the value 100, and so on.

The formula for calculating the start parameter value:

start = (N-1) * 50, where N — the number of the desired page

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
type

Description

result
array

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 select parameter.

For information about the structure of a lead, see the method crm.lead.get

total
integer

The total number of found items

next
integer

Contains the value to be passed in the next request in the start parameter to get the next batch of data.

The next parameter appears in the response if the number of items matching your request exceeds 50

time
time

Information about the execution time of the request

Error Handling

HTTP Status: 40x, 50x Error

{
            "error": "",
            "error_description": "Access denied."
        }
        

Name
type

Description

error
string

String error code. It may consist of digits, Latin letters, and underscores

error_description
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

Access denied

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
Error Message

Description

500

INTERNAL_SERVER_ERROR
Internal server error

An internal server error has occurred, please contact the server administrator or Bitrix24 technical support

500

ERROR_UNEXPECTED_ANSWER
Server returned an unexpected response

An internal server error has occurred, please contact the server administrator or Bitrix24 technical support

503

QUERY_LIMIT_EXCEEDED
Too many requests

The request intensity limit has been exceeded

405

ERROR_BATCH_METHOD_NOT_ALLOWED
Method is not allowed for batch usage

The current method is not allowed to be called using batch

400

ERROR_BATCH_LENGTH_EXCEEDED
Max batch length exceeded

The maximum length of parameters passed to the batch method has been exceeded

401

NO_AUTH_FOUND
Wrong authorization data

Invalid access token or webhook code

400

INVALID_REQUEST
Https required

The methods must be called using the HTTPS protocol

503

OVERLOAD_LIMIT
REST API is blocked due to overload

The REST API is blocked due to overload. This is a manual individual block, to remove it you need to contact Bitrix24 technical support

403

ACCESS_DENIED
REST API is available only on commercial plans

The REST API is available only on commercial plans

403

INVALID_CREDENTIALS
Invalid request credentials

The user whose access token or webhook was used to call the method lacks permissions

404

ERROR_MANIFEST_IS_NOT_AVAILABLE
Manifest is not available

The manifest is not available

403

insufficient_scope
The request requires higher privileges than provided by the webhook token

The request requires higher privileges than those provided by the webhook token

401

expired_token
The access token provided has expired

The provided access token has expired

403

user_access_error
The user does not have access to the application

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

500

PORTAL_DELETED
Portal was deleted

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

Continue Learning