Skip to main content
Version: 1.1.0-beta

Response object

We've created a unified response object that will get returned from all methods in the SDK that communicates with the API. Using this object is default behaviour, but it can be changed by setting the "responseObjectType" configuration option when initializing the client.

Example#

use Servebolt\Sdk\Client;$client = new Client(['apiToken'   => 'your-api-token']);$response = $client->cron->list();
if ($response->hasErrors()) {    $errors = $response->getErrors();    // Display errors} elseif ($response->wasSuccessful()) {    if ($response->hasMessages()) {        $messages = $response->getMessages();        // Display messages           }    $cronJobs = $response->getResultItems();    // Do something with the cronjobs}

Available methods#

$response->getStatusCode() : bool // Get HTTP status code (if present)
$response->wasSuccessful() : bool
$response->getRawResponse() : object // Use this to get the JSON decoded response from the HTTP request
$response->isMultiple() : bool
$response->isIterable() : bool // Alias of "isMultiple"
$response->hasResult() : bool
$response->countResultItems() : int
$response->getResultItems()
$response->getFirstResultItem()

Message handling#

$response->hasMessages() : bool
$response->getMessages() : array
$response->hasSingleMessage() : bool
$response->getFirstMessage() : array

Error handling#

$response->hasErrors() : bool
$response->getErrors() : array
$response->hasSingleError() : bool
$response->getFirstError()
$response->getFirstErrorMessage()
$response->getFirstErrorCode()