bynder/bynder-php-sdk
The Bynder PHP SDK speeds up integrating Bynder with PHP, making it easier to connect to the Bynder API and execute requests. Install via Composer, configure your domain, redirect URI, client ID, and secret, and use Guzzle request options.
Check the PHP requirement first (changed in 2.2.8) Since v2.2.8 the SDK requires PHP 8.2+ (it was 8.1 before) and is CI-tested against PHP 8.5. Before installing, verify your runtime:
php -v # must be 8.2.x or higher
composer check-platform-reqs
Practical impact for Laravel apps:
bynder/bynder-php-sdk:2.2.7)."bynder/bynder-php-sdk": "2.2.7" until the image is updated.Installation Add the SDK via Composer:
composer require bynder/bynder-php-sdk
Confirm the resolved version is 2.2.8 (composer show bynder/bynder-php-sdk) and that the package is autoloaded in composer.json under autoload.psr-4.
Configuration
Create a .env entry for Bynder credentials:
BYNDER_CLIENT_ID=your_client_id
BYNDER_CLIENT_SECRET=your_client_secret
BYNDER_REDIRECT_URI=http://your-app.dev/bynder/callback
BYNDER_BASE_URL=https://api.bynder.com/v2
First Use Case: OAuth Authentication Initialize the client in a Laravel service:
use Bynder\BynderClient;
$client = new BynderClient(
config('bynder.client_id'),
config('bynder.client_secret'),
config('bynder.redirect_uri'),
config('bynder.base_url')
);
Redirect users to Bynder for auth:
return redirect()->to($client->getAuthorizationUrl());
Handle the callback in a route:
Route::get('/bynder/callback', function () {
$client = app(BynderClient::class);
$token = $client->handleAuthorizationCallback(request()->query('code'));
session(['bynder_token' => $token]);
});
Asset Management
$asset = $client->assets()->upload(
file_get_contents('path/to/file.jpg'),
'image/jpeg',
['name' => 'example.jpg', 'description' => 'Test upload']
);
$assets = $client->assets()->getAll(['limit' => 10]);
foreach ($assets as $asset) {
$downloadUrl = $client->assets()->getDownloadUrl($asset['id']);
}
Collections
$collection = $client->collections()->create([
'name' => 'Project Assets',
'description' => 'Assets for Project X'
]);
$client->collections()->addAssets($collection['id'], [$assetId1, $assetId2]);
Webhooks
Route::post('/bynder/webhook', function (Request $request) {
$client->webhooks()->verifySignature($request->header('X-Bynder-Signature'), $request->getContent());
// Process payload
});
Integration with Laravel Storage
$assetData = $client->assets()->download($assetId);
Storage::disk('bynder')->put($assetId, $assetData);
oauth_tokens table) with TTL handling.try {
$asset = $client->assets()->upload(...);
} catch (BynderException $e) {
Log::error("Bynder upload failed: " . $e->getMessage());
throw new \Exception("Failed to upload asset", 0, $e);
}
PHP 8.1 support dropped in 2.2.8
Your requirements could not be resolved ... requires php >=8.2). If you see this on a machine that "used to work", it's the platform, not the package.php:8.1-fpm), Laravel Sail/Homestead VMs, and config.platform.php in composer.json pinning 8.1 in production builds. Update all four or pin 2.2.7 deliberately.composer update will pick it up without a warning — a routine composer update can break a deploy. Lock step your PHP upgrade and the SDK bump in the same PR.<8.2 (old PHPUnit, PHPStan, or a stalled transitive package) will now block the resolver; upgrade tooling alongside.OAuth Flow Quirks
redirect_uri in the SDK matches the one registered in Bynder’s developer portal. Mismatches result in invalid_redirect_uri errors.state parameter in the auth URL to prevent CSRF. Use Laravel’s csrf_token():
$authUrl = $client->getAuthorizationUrl(['state' => csrf_token()]);
Token Expiry
refreshToken() call before expiry or use a job queue to refresh tokens proactively.refresh_token alongside the access token for silent refreshes.API Versioning
v2 of the Bynder API. If migrating to v3, update the base_url in config and handle breaking changes (e.g., endpoint paths like /assets → /v3/assets).File Size Limits
$client = new BynderClient(..., ..., ..., [
'logger' => function ($message) {
Log::debug('Bynder SDK: ' . $message);
}
]);
BynderException with raw responses. Log the $e->getResponse() property for debugging.composer show bynder/bynder-php-sdk on each box — mixed 2.2.7/2.2.8 across app, queue workers, and scheduled jobs is the usual culprit.Custom HTTP Client Override the default Guzzle client for retries or middleware:
$client = new BynderClient(..., ..., ..., [
'http_client' => new \GuzzleHttp\Client([
'timeout' => 30,
'headers' => ['User-Agent' => 'MyApp/1.0']
])
]);
Event Dispatching
Trigger Laravel events for SDK actions (e.g., asset.uploaded):
$client->assets()->upload(..., function ($asset) {
event(new AssetUploaded($asset));
});
Local Testing
Use Bynder’s sandbox environment with mock credentials. Override the base_url in config:
BYNDER_BASE_URL=https://sandbox.bynder.com/v2
Wrap the client once
Bind BynderClient as a singleton in a service provider and inject it everywhere. That gives you a single place to swap in a fake, change the HTTP client, or pin behaviour when the next runtime bump lands.
How can I help you explore Laravel packages today?