PHP SDK
The Goomzo API for PHP.
goomzo/goomzo-php is the Goomzo API for PHP. It retries safely, pages through lists for you, and turns errors into
exceptions you can act on. It works with Laravel, Symfony or plain PHP.
Requirements
- PHP 8.1 or later, with Composer.
- An API key. See Authentication.
Install
composer require goomzo/goomzo-phpMake your first request
Set your API key's secret as GOOMZO_API_KEY, then send a message:
use Goomzo\Goomzo;
$goomzo = new Goomzo();
$message = $goomzo->messages->sendOne([
'to' => '+255712345678',
'channel' => 'sms',
'content' => ['text' => 'Amina, order #1042 is ready.'],
]);
echo $message['id'], ' ', $message['status'];How it reads
- Requests and answers are arrays, with the API's own keys, exactly as in its JSON, such as
customerIdandsendAt. They match the requests in these docs one for one. - Options are named arguments, such as
idempotencyKey: 'order-1042'. - Lists that can be long come as a page you can loop over.
What it does for you
- A fixed version: it pins the API version it was written for, so a new version never changes what your code gets.
- Safe retries: network errors,
429and5xxare tried again, twice by default. EveryPOSTcarries anIdempotency-Key, the same on each try, so nothing is done twice. - Errors you can act on: an
ApiExceptionhas thestatus, theerrorCode, thefieldsthat were wrong and therequestId.
Next steps
Last updated