API Client
Filter contacts list

When using Model::getList() method, you may want to retrieve records matching a specific criteria. Use 'filters' option for this purpose.

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

Output:

1 There are 3 contacts in total
2 [
3  {
4  "first_name": "Johnathan",
5  "last_name": "Burgher",
6  "id": "53e82904-1b6d-3771-654e-5aa798c22995",
7  "name": "Johnathan Burgher",
8  "salutation": null,
9  "_display": "Johnathan Burgher"
10  },
11  {
12  "first_name": "John",
13  "last_name": "Eastham",
14  "id": "9d501f39-1b86-7c7d-42aa-5aa79802c8b9",
15  "name": "John Eastham",
16  "salutation": null,
17  "_display": "John Eastham"
18  },
19  {
20  "first_name": "John",
21  "last_name": "Smith",
22  "id": "a7be92d7-9870-b338-bf04-5348d0b8836f",
23  "name": "John Smith",
24  "salutation": null,
25  "_display": "John Smith"
26  }
27 ]
Note
You cannot use arbitrary fields for filtering. To get a list of available filters, use Model::metadata() method. In 1CRM Enterprise edition, you can use Module Designer to enable filtering by arbitrary fields.