Skip to main content
Testing webhooks requires a different approach than testing typical API integrations. Since webhooks are push-based, your local development server isn’t directly accessible from Lettr’s servers. This guide covers strategies for testing webhooks at every stage of development.

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.
  1. Install ngrok:
  1. Start your local server:
  1. Create a tunnel:
  1. Copy the HTTPS URL:
  1. 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).
Use ngrok’s paid plan to get a stable subdomain. Free URLs change each time you restart ngrok.

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 authentic message.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

  1. 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
  2. Verify SSL certificate - Ensure your staging environment has a valid SSL certificate
  3. Test all event types - Send test events for each type you handle
  4. Test retry handling - Temporarily return errors to verify retry behavior
  5. Test authentication - Confirm your staging environment uses the correct webhook credentials
  6. 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:
  1. Get a temporary URL from Webhook.site
  2. Configure a test webhook to that URL
  3. Send test events and inspect the raw requests
  4. Copy the payload structure for your tests

Dashboard Webhook Details

The Lettr dashboard shows webhook status information:
  1. Go to Webhooks in the sidebar
  2. Select your webhook
  3. View the webhook details including last attempt time, last status, and enabled state

Common Testing Pitfalls

Never commit webhook authentication credentials to source control. Use environment variables.
Always test that your handler correctly handles duplicate events.
Test what happens when downstream services fail.

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