-
Notifications
You must be signed in to change notification settings - Fork 2
Responses
For successful calls, 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.
If we fetch a single user, our response will be a User model:
$user = $api->getUser(123);Model data can be accessed via getters methods:
$firstname = $user->getFirstname(); // 'John'
$lastname = $user->getLastname(); // 'Doe'
$formattedName = $user->getFormattedName(); // 'John Doe'
$active = $user->getActive(); // 1* The attributes returned from the API use snake_case while the getters defined in this library use camelCase.
If we fetch multiple users, our response will be a collection which contains an array of User models:
$users = $api->getUsers();The collection class contains the following 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->getModels();
foreach ($models as $model) {
...
}Each model in the array can be handled in the same way as described above.
For API calls that fail or error for some reason, a \SupportPal\ApiClient\Exception\HttpResponseException exception is raised. The exception message will contain the error message delivered from the API.