Local Development
During local development, you need a way to receive webhooks on your machine. There are several approaches.Using ngrok
ngrok creates a secure tunnel from a public URL to your local server, allowing Lettr to send webhooks directly to your development machine.- Install ngrok:
- Start your local server:
- Create a tunnel:
- Copy the HTTPS URL:
- Configure webhook in Lettr: Go to Webhooks in the sidebar and create a new webhook pointing to your ngrok URL (e.g.,
https://abc123.ngrok.io/webhooks/lettr).
Using Cloudflare Tunnel
Cloudflare Tunnel provides a similar capability:Using localtunnel
localtunnel is a free, open-source alternative:Triggering Test Events
The simplest way to trigger real webhook events during testing is to send an actual email through the API. This generates authenticmessage.injection and message.delivery (or message.bounce) events that are delivered to your webhook endpoint:
Unit Testing Your Handler
Test your webhook handler logic without making real HTTP requests.Basic Unit Test
Testing Authentication Verification
If your webhook uses basic authentication, test that your handler correctly verifies credentials:Integration Testing
Test the full webhook flow including HTTP handling.Using Supertest
End-to-End Testing
Test the complete flow from sending an email to receiving webhooks.Trigger Real Events
Send actual emails to trigger genuine webhook events:Webhook Collector Helper
Create a helper to capture webhooks during tests:Staging Environment Testing
Before deploying to production, test webhooks in a staging environment.Checklist
-
Configure staging webhook endpoint in the Lettr dashboard, pointing to your staging URL (e.g.,
https://staging.example.com/webhooks/lettr) and subscribing to all events - Verify SSL certificate - Ensure your staging environment has a valid SSL certificate
- Test all event types - Send test events for each type you handle
- Test retry handling - Temporarily return errors to verify retry behavior
- Test authentication - Confirm your staging environment uses the correct webhook credentials
- Load testing - Send multiple webhooks to test concurrent handling
Simulating Failures
Test how your system handles webhook failures:Debugging Webhooks
Logging Incoming Webhooks
Add comprehensive logging during development:Request Inspection Tools
Use tools like Webhook.site or RequestBin to inspect webhook payloads:- Get a temporary URL from Webhook.site
- Configure a test webhook to that URL
- Send test events and inspect the raw requests
- Copy the payload structure for your tests
Dashboard Webhook Details
The Lettr dashboard shows webhook status information:- Go to Webhooks in the sidebar
- Select your webhook
- View the webhook details including last attempt time, last status, and enabled state
Common Testing Pitfalls
Hardcoded credentials in production
Hardcoded credentials in production
Never commit webhook authentication credentials to source control. Use environment variables.
Not testing idempotency
Not testing idempotency
Always test that your handler correctly handles duplicate events.
Not testing error scenarios
Not testing error scenarios
Test what happens when downstream services fail.
Related Topics
Handling Webhooks
Best practices for processing webhooks reliably
Authorization
Secure your endpoints with authentication
Retries
Understand retry behavior and failure handling
Event Types
Complete reference of all webhook events