github getbrevo/brevo-php v4.0.5

5 hours ago

📦 Brevo PHP SDK v4.0.5

Modernized, type-safe rewrite of the Brevo PHP client with a unified client architecture, PSR-18 compatibility, and built-in reliability features.


🚀 Highlights

  • Type-safe SDK with strongly typed request/response objects and PHPDoc annotations
  • Single unified client (Brevo) replaces multiple API classes and manual configuration
  • Built-in retries + timeouts
  • Structured error handling
  • PSR-18 compatible — works with Guzzle, Symfony HttpClient, or any PSR-18 implementation
  • PHP 8.1+ with support for Laravel, Symfony, and plain PHP
  • Legacy v2.x now maintenance-only

⚠️ Breaking Changes

This is a full rewrite of the SDK. v4.0.5 is not backwards compatible with v2.x.

Key breaking changes:

  • The multi-class initialization pattern (Configuration::getDefaultConfiguration() + per-API class instantiation) is replaced by a single Brevo client
  • Setter-based request building (e.g., $message->setSubject(...)) is replaced by typed request objects with named constructors
  • Error handling now uses BrevoApiException / BrevoException instead of Guzzle-specific exceptions
  • The SDK now requires PHP 8.1+ (previously PHP 7.x)
  • PSR-18 HTTP client replaces the hard Guzzle dependency

The legacy v2.x SDK will continue to receive critical security updates but no new features. We strongly recommend migrating to v4.x.


Added

New Client Architecture

  • Introduced Brevo as the single entry point
  • Namespaced API clients (e.g., $brevo->transactionalEmails->*, $brevo->contacts->*)
  • 30+ resource clients accessible from one instance: contacts, deals, campaigns, ecommerce, webhooks, and more

Type Safety

  • Strongly typed request and response classes for every endpoint
  • Full PHPDoc annotations for IDE autocomplete
  • Named constructors with typed arrays replace untyped setters

Reliability Features

  • Automatic retries with exponential backoff and jitter (~1s, ~2s, ~4s)
  • Honors Retry-After headers on rate-limited responses
  • Configurable global and per-request timeouts (default: 60s)
  • Retryable status codes: 408, 429, 500, 502, 503, 504

Error Handling

  • BrevoApiException for all non-2xx API responses with:
    • getCode() — HTTP status code
    • getMessage() — error message
    • getBody() — parsed error response body
  • BrevoException as a base for all SDK-level errors
  • Clean try/catch branching by status code

Advanced Configuration

  • Custom PSR-18 HTTP client support (Guzzle, Symfony HttpClient, etc.)
  • Custom headers at client and per-request level
  • Configurable base URL
  • Binary response support for file downloads

Runtime Compatibility

  • PHP 8.1+
  • Laravel
  • Symfony
  • Any framework or plain PHP project with Composer

Read more at https://developers.brevo.com/docs/api-clients/php

Don't miss a new brevo-php release

NewReleases is sending notifications on new releases.