List, create, update, and delete webhooks with the Lettr PHP SDK
Webhooks deliver real-time notifications when emails are delivered, opened, clicked, bounced, or marked as spam. The $lettr->webhooks() service manages your webhook endpoints programmatically.For the event payload format and signature verification, see Webhooks.
use Lettr\Dto\Webhook\CreateWebhookData;use Lettr\Enums\WebhookAuthType;use Lettr\Enums\WebhookEventsMode;use Lettr\Enums\WebhookEventType;// Subscribe to specific events$webhook = $lettr->webhooks()->create(new CreateWebhookData( name: 'Production events', url: 'https://example.com/webhooks/lettr', authType: WebhookAuthType::None, eventsMode: WebhookEventsMode::Selected, events: [ WebhookEventType::MessageDelivery, WebhookEventType::MessageBounce, WebhookEventType::EngagementClick, ],));echo $webhook->id;echo $webhook->url;
Use WebhookEventsMode::All to receive every event type (no events array needed), or WebhookEventsMode::Selected with an explicit events array for a subset. For authenticated endpoints, set authType to WebhookAuthType::Basic or WebhookAuthType::OAuth2 and supply the matching credential fields (authUsername/authPassword or the oauth* fields).
use Lettr\Enums\WebhookEventType;$webhook = $lettr->webhooks()->get('webhook-id');echo $webhook->name;echo $webhook->url;echo $webhook->lastStatus?->value;echo $webhook->lastSuccessfulAt;echo $webhook->lastFailureAt;// Check if the webhook listens to a specific eventif ($webhook->listensTo(WebhookEventType::MessageBounce)) { echo "Webhook receives bounce notifications";}