Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Bynder Php Sdk Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

First Steps

  1. Installation Add the SDK via Composer:

    composer require bynder/bynder-php-sdk
    

    Verify the package is autoloaded in composer.json under autoload.psr-4.

  2. 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
    
  3. 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]);
    });
    

Implementation Patterns

Common Workflows

  1. Asset Management

    • Uploading Assets:
      $asset = $client->assets()->upload(
          file_get_contents('path/to/file.jpg'),
          'image/jpeg',
          ['name' => 'example.jpg', 'description' => 'Test upload']
      );
      
    • Fetching Assets:
      $assets = $client->assets()->getAll(['limit' => 10]);
      foreach ($assets as $asset) {
          $downloadUrl = $client->assets()->getDownloadUrl($asset['id']);
      }
      
  2. Collections

    • Create/update collections:
      $collection = $client->collections()->create([
          'name' => 'Project Assets',
          'description' => 'Assets for Project X'
      ]);
      
    • Add assets to collections:
      $client->collections()->addAssets($collection['id'], [$assetId1, $assetId2]);
      
  3. Webhooks

    • Register a webhook endpoint in Laravel:
      Route::post('/bynder/webhook', function (Request $request) {
          $client->webhooks()->verifySignature($request->header('X-Bynder-Signature'), $request->getContent());
          // Process payload
      });
      
  4. Integration with Laravel Storage

    • Use the SDK to proxy downloads to Laravel’s filesystem:
      $assetData = $client->assets()->download($assetId);
      Storage::disk('bynder')->put($assetId, $assetData);
      

Best Practices

  • Token Management: Store tokens in the database (e.g., oauth_tokens table) with TTL handling.
  • Rate Limiting: Implement middleware to respect Bynder’s rate limits.
  • Error Handling: Wrap SDK calls in try-catch blocks:
    try {
        $asset = $client->assets()->upload(...);
    } catch (BynderException $e) {
        Log::error("Bynder upload failed: " . $e->getMessage());
        throw new \Exception("Failed to upload asset", 0, $e);
    }
    

Gotchas and Tips

Pitfalls

  1. OAuth Flow Quirks

    • Redirect URI Mismatch: Ensure the redirect_uri in the SDK matches the one registered in Bynder’s developer portal. Mismatches result in invalid_redirect_uri errors.
    • State Parameter: Always include a state parameter in the auth URL to prevent CSRF. Use Laravel’s csrf_token():
      $authUrl = $client->getAuthorizationUrl(['state' => csrf_token()]);
      
  2. Token Expiry

    • Tokens expire after 30 days (default). Implement a refreshToken() call before expiry or use a job queue to refresh tokens proactively.
    • Store the refresh_token alongside the access token for silent refreshes.
  3. API Versioning

    • The SDK defaults to 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).
  4. File Size Limits

    • Bynder enforces a 5GB upload limit. For larger files, use chunked uploads or Bynder’s presigned URLs.

Debugging Tips

  • Enable Verbose Logging:
    $client = new BynderClient(..., ..., ..., [
        'logger' => function ($message) {
            Log::debug('Bynder SDK: ' . $message);
        }
    ]);
    
  • Inspect Raw Responses: The SDK throws BynderException with raw responses. Log the $e->getResponse() property for debugging.

Extension Points

  1. 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']
        ])
    ]);
    
  2. Event Dispatching Trigger Laravel events for SDK actions (e.g., asset.uploaded):

    $client->assets()->upload(..., function ($asset) {
        event(new AssetUploaded($asset));
    });
    
  3. Local Testing Use Bynder’s sandbox environment with mock credentials. Override the base_url in config:

    BYNDER_BASE_URL=https://sandbox.bynder.com/v2
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky