bynder/bynder-php-sdk
PHP SDK for integrating Bynder’s DAM platform. Manage assets, collections, metadata, and uploads/downloads via the Bynder API. Includes authentication helpers and convenient client methods for common media management workflows.
Installation Add the SDK via Composer:
composer require bynder/bynder-php-sdk
Verify 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);
}
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.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
How can I help you explore Laravel packages today?