sendboo / sendboo-php
Framework-agnostic PHP client for the Sendboo API: track events and sync subscribers from any website.
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.5
Requires (Dev)
- phpunit/phpunit: ^10.5
This package is not auto-updated.
Last update: 2026-06-19 05:26:22 UTC
README
PHP client for the Sendboo API. Track events and sync subscribers from any website.
Install
composer require sendboo/sendboo-php
Authenticate
You need a Sendboo API token plus your organization (and store) UUIDs. They map to the Authorization: Bearer, X-Organization-Id and X-Store-Id headers the API expects.
use Sendboo\Sendboo; $sendboo = new Sendboo( token: '123|sb_...', organizationId: 'org-uuid', storeId: 'store-uuid', // optional; required for events & subscribers );
Track events
Identify the actor with an anonymous_id (a visitor id you generate) or a subscriber_id. source defaults to php and occurred_at to now.
$sendboo->track('purchase_completed', [ 'anonymous_id' => $visitorId, 'properties' => ['order_id' => 1234, 'total' => 79.90], ]);
Sync subscribers
sync() upserts every row into a Sendboo email list. Pass unsubscribeMissing: true to also unsubscribe people who are on the list but no longer in your data (drift removal, off by default because it's destructive).
// Build the list however you fetch subscribers — here from a plain PDO query. $rows = []; foreach ($pdo->query('SELECT email, first_name, plan FROM users WHERE subscribed = 1') as $user) { $rows[] = [ 'email' => $user['email'], 'first_name' => $user['first_name'], 'tags' => $user['plan'] === 'pro' ? ['pro'] : [], ]; } $result = $sendboo->subscribers()->sync('email-list-uuid', $rows, unsubscribeMissing: true); // ['upserted' => 1200, 'unsubscribed' => 7]
Laravel
The package is framework-agnostic, but in a Laravel app you can build the rows with an Eloquent collection:
$rows = User::where('subscribed', true)->get() ->map(fn (User $user) => [ 'email' => $user->email, 'first_name' => $user->first_name, 'tags' => $user->plan === 'pro' ? ['pro'] : [], ]) ->all(); $sendboo->subscribers()->sync('email-list-uuid', $rows, unsubscribeMissing: true);
Scheduled sync (Laravel)
The package is framework-agnostic, but a common setup is a Laravel Artisan command that keeps a Sendboo email list in step with your users. Generate it with php artisan make:command SyncSendboo:
<?php namespace App\Console\Commands; use App\Models\User; use Illuminate\Console\Command; use Sendboo\Sendboo; class SyncSendboo extends Command { protected $signature = 'sendboo:sync'; protected $description = 'Sync subscribed users to the Sendboo email list'; public function handle(): int { $sendboo = new Sendboo( token: config('services.sendboo.token'), organizationId: config('services.sendboo.organization_id'), storeId: config('services.sendboo.store_id'), ); $rows = User::where('subscribed', true)->get() ->map(fn (User $user) => [ 'email' => $user->email, 'first_name' => $user->first_name, 'tags' => $user->plan === 'pro' ? ['pro'] : [], ]) ->all(); $result = $sendboo->subscribers()->sync( config('services.sendboo.list_uuid'), $rows, unsubscribeMissing: true, ); $this->info("Synced {$result['upserted']}, unsubscribed {$result['unsubscribed']}."); return self::SUCCESS; } }
Add the credentials to config/services.php:
'sendboo' => [ 'token' => env('SENDBOO_TOKEN'), 'organization_id' => env('SENDBOO_ORG_ID'), 'store_id' => env('SENDBOO_STORE_ID'), 'list_uuid' => env('SENDBOO_LIST_UUID'), ],
Then schedule it in routes/console.php:
use Illuminate\Support\Facades\Schedule; Schedule::command('sendboo:sync')->dailyAt('03:00');
Manage individual subscribers
$subscribers = $sendboo->subscribers(); $subscribers->upsert('email-list-uuid', [ 'email' => 'jane@example.com', 'first_name' => 'Jane', 'tags' => ['vip'], 'extra_attributes' => ['plan' => 'pro'], 'skip_confirmation' => true, ]); $subscribers->unsubscribe('email-list-uuid', 'jane@example.com'); foreach ($subscribers->all('email-list-uuid') as $subscriber) { // ... }
Errors
Non-2xx responses throw Sendboo\Exceptions\SendbooException with ->status
and the decoded ->response body.
Test
composer install
composer test