Skip to content

Responses

Jay edited this page Oct 22, 2020 · 8 revisions

Depending on the function called, the response from the client will either be a single model or a \SupportPal\ApiClient\Model\Collection\Collection object, which is a collection of models.

Models

If we fetch a single user, our response will be a User model:

$user = $api->getUser(123);

We would be able to access the attributes on the model using getters:

$firstname = $user->getFirstname(); // 'John'
$lastname = $user->getLastname(); // 'Doe'

$formattedName = $user->getFormattedName(); // 'John Doe'

$active = $user->getActive(); // 1

Collections

If we fetch multiple users, our response will be a collection which contains an array of User models:

$users = $api->getUsers();

Our collection class will contain three attributes:

// The total number of records that were found for this endpoint, not considering the `limit` or `start` options. Useful for pagination.
$count = $users->getCount(); // 1000

// The total number of models included in the response data.
$modelsCount = $users->getModelsCount(); // 50

// An array of models.
$models = $users->getCount();

Each model in the array can handled in the same way as listed above.