API Client
Retrieving list of records

To fetch a list of records, use the Model::getList() method. It returns an instance of ListResult class.

$model = $client->model('Contact');
$result = $model->getList([], 0, 2);
echo $result->totalResults(), "\n";
echo json_encode($result->getRecords(), JSON_PRETTY_PRINT);
1 200
2 [
3  {
4  "name": "Kristina Abramowitz",
5  "first_name": "Kristina",
6  "id": "7eba2a01-6cb6-f38c-d4c2-5a8fc2def9d2",
7  "last_name": "Abramowitz",
8  "salutation": null,
9  "_display": "Kristina Abramowitz"
10  },
11  {
12  "name": "Garret Alejo",
13  "first_name": "Garret",
14  "id": "346ba8d2-2851-166b-13e6-5a8fc2c18299",
15  "last_name": "Alejo",
16  "salutation": null,
17  "_display": "Garret Alejo"
18  }
19 ]

Here we specify that we want to start from first record (0 is passed in $offset argument), and we want no more than 2 rescords returned (2 is passed in $limit argument). totalResults() returned 200, telling us that there is more data available. If we want to retrieve next 2 records, we have to make another request, passing 2 in $offset:

$result = $model->getList([], 2, 2);

Model::getist() accepts an array of options that can be used to refine the request.

filter_text option

Use the filter_text option for generic text search:

$model = $client->model('Contact');
$result = $model->getList(['filter_text' => 'Michael'], 0, 2);
echo $result->totalResults(), "\n";
echo json_encode($result->getRecords(), JSON_PRETTY_PRINT);
1 1
2 [
3  {
4  "name": "Michael Whitehead",
5  "first_name": "Michael",
6  "id": "4ec8fd9d-d035-839e-5356-5a8fc2480082",
7  "last_name": "Whitehead",
8  "salutation": null,
9  "_display": "Michael Whitehead"
10  }
11 ]

filters option

Use the filters option to filter data:

$model = $client->model('Contact');
$result = $model->getList(['filters' => ['address_city' => 'San Jose']], 0, 2);
echo $result->totalResults(), "\n";
echo json_encode($result->getRecords(), JSON_PRETTY_PRINT);
1 15
2 [
3  {
4  "name": "Kristina Abramowitz",
5  "first_name": "Kristina",
6  "id": "7eba2a01-6cb6-f38c-d4c2-5a8fc2def9d2",
7  "last_name": "Abramowitz",
8  "salutation": null,
9  "_display": "Kristina Abramowitz"
10  },
11  {
12  "name": "Emma Alley",
13  "first_name": "Emma",
14  "id": "c1edefc7-5595-e61e-0fd9-5a8fc2333dcc",
15  "last_name": "Alley",
16  "salutation": null,
17  "_display": "Emma Alley"
18  }
19 ]

Another example:

$model = $client->model('Contact');
$result = $model->getList(['filters' => ['filter_favorites' => true]], 0, 2);
echo $result->totalResults(), "\n";
echo json_encode($result->getRecords(), JSON_PRETTY_PRINT);
1 1
2 [
3  {
4  "name": "Kristina Abramowitz",
5  "first_name": "Kristina",
6  "id": "7eba2a01-6cb6-f38c-d4c2-5a8fc2def9d2",
7  "last_name": "Abramowitz",
8  "salutation": null,
9  "_display": "Kristina Abramowitz",
10  "favorite": "0"
11  }
12 ]

order option

Use the order option to return the data in specific order:

$model = $client->model('Contact');
$result = $model->getList(['order' => 'last_name DESC'], 0, 2);
echo $result->totalResults(), "\n";
echo json_encode($result->getRecords(), JSON_PRETTY_PRINT);
1 200
2 [
3  {
4  "name": "Arron Ybanez",
5  "first_name": "Arron",
6  "id": "a8a157b1-a20a-3023-fc7a-5a8fc28d2b4a",
7  "last_name": "Ybanez",
8  "salutation": null,
9  "_display": "Arron Ybanez"
10  },
11  {
12  "name": "Dario Yan",
13  "first_name": "Dario",
14  "id": "15a7fc37-2711-5b54-af16-5a8fc27fb778",
15  "last_name": "Yan",
16  "salutation": null,
17  "_display": "Dario Yan"
18  }
19 ]

fields option

Use the fields option to specify a list of fields you want to fetch:

$model = $client->model('Contact');
$result = $model->getList(['fields' => ['first_name', 'last_name', 'primary_address_city']], 0, 2);
echo $result->totalResults(), "\n";
echo json_encode($result->getRecords(), JSON_PRETTY_PRINT);
1 200
2 [
3  {
4  "first_name": "Kristina",
5  "last_name": "Abramowitz",
6  "primary_address_city": "San Jose",
7  "id": "7eba2a01-6cb6-f38c-d4c2-5a8fc2def9d2",
8  "name": "Kristina Abramowitz",
9  "salutation": null,
10  "_display": "Kristina Abramowitz"
11  },
12  {
13  "first_name": "Garret",
14  "last_name": "Alejo",
15  "primary_address_city": "Cupertino",
16  "id": "346ba8d2-2851-166b-13e6-5a8fc2c18299",
17  "name": "Garret Alejo",
18  "salutation": null,
19  "_display": "Garret Alejo"
20  }
21 ]

query_favorite option

Use the query_favorite option if you want a flag returned for each record telling if the record was added to favorites:

$model = $client->model('Contact');
$result = $model->getList(['query_favorite' => true], 0, 2);
echo $result->totalResults(), "\n";
echo json_encode($result->getRecords(), JSON_PRETTY_PRINT);
1 200
2 [
3  {
4  "name": "Kristina Abramowitz",
5  "first_name": "Kristina",
6  "id": "7eba2a01-6cb6-f38c-d4c2-5a8fc2def9d2",
7  "last_name": "Abramowitz",
8  "salutation": null,
9  "_display": "Kristina Abramowitz",
10  "favorite": "0"
11  },
12  {
13  "name": "Garret Alejo",
14  "first_name": "Garret",
15  "id": "346ba8d2-2851-166b-13e6-5a8fc2c18299",
16  "last_name": "Alejo",
17  "salutation": null,
18  "_display": "Garret Alejo",
19  "favorite": null
20  }
21 ]
Attention
Records added to favorites will have favorite field with value of "0"