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);
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
4 "first_name": "Johnathan",
5 "last_name": "Burgher",
6 "id": "53e82904-1b6d-3771-654e-5aa798c22995",
7 "name": "Johnathan Burgher",
9 "_display": "Johnathan Burgher"
13 "last_name": "Eastham",
14 "id": "9d501f39-1b86-7c7d-42aa-5aa79802c8b9",
15 "name": "John Eastham",
17 "_display": "John Eastham"
22 "id": "a7be92d7-9870-b338-bf04-5348d0b8836f",
25 "_display": "John Smith"
- 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.