API Client
Retrieve leads list

This is a basic example of retrieving a list of records using 1CRM API.

Use Model::getList() method.

It is normally a good idea to specify a list of fields you are interested in, otherwise only a limited subset of fields will be returned. The order in which the records are returned depends on the model used. See other examples to learn how to specify sort order.

Also, you may want to specify offset and limit to retrieve a limited number of records.

Note that getList() returns an instance of ListResult. To get an array with records, use getRecords() methods. To know how many records there are in total, ignoring the limit, use totalResults() method.

$model = $client->model('Lead');
$fields = ['first_name', 'last_name', 'email1'];
$result = $model->getList(['fields' => $fields], 0, 3); // fetch no more than 3 records, starting from the beginning
printf("There are %d leads in total\n", $result->totalResults());
echo json_encode($result->getRecords(), JSON_PRETTY_PRINT), "\n";

Output:

1 There are 38 leads in total
2 [
3  {
4  "first_name": "Laurie",
5  "last_name": "Giusti",
6  "email1": "mobile52@example.com.au",
7  "id": "4158ca78-6f11-ac08-3620-5aa7989bfe31",
8  "name": "Laurie Giusti",
9  "salutation": null,
10  "_display": "Laurie Giusti"
11  },
12  {
13  "first_name": "Maximo",
14  "last_name": "Spradlin",
15  "email1": "fitness.hr@example.us",
16  "id": "43950469-288d-6250-713f-5aa798bd0dd1",
17  "name": "Maximo Spradlin",
18  "salutation": null,
19  "_display": "Maximo Spradlin"
20  },
21  {
22  "first_name": "Marisol",
23  "last_name": "Mole",
24  "email1": "fitness24@example.info",
25  "id": "45cc3a29-11fd-0945-b759-5aa79876fb6d",
26  "name": "Marisol Mole",
27  "salutation": null,
28  "_display": "Marisol Mole"
29  }
30 ]