> For the complete documentation index, see [llms.txt](https://help.lob.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.lob.com/print-and-mail/getting-data-and-results/using-webhooks.md). Agents can also search and read this documentation through its [MCP server](https://help.lob.com/~gitbook/mcp).

# Using webhooks

### Overview

A webhook lets one service send real-time updates to another automatically. Lob uses webhooks to tell you about events on your account, including USPS tracking events. See the [full list of events](https://docs.lob.com/#tag/Webhooks).

Common uses:

* Finding out when a mail piece fails to render
* Downloading PDF previews or thumbnails automatically after rendering
* Telling your end users where their mail is in the postal stream
* Starting a downstream workflow when mail is Delivered
* Getting alerts for scans like Re-Routed or Returned to Sender
* Internal logging and reconciliation

When an event happens and you have a webhook subscribed to that event type in that environment (Test or Live), Lob sends a POST request with the full [event object](https://docs.lob.com/#event_object) to your URL. See [Events](https://docs.lob.com/#tag/Events) for details.

### Subscribing to a webhook in the Lob dashboard

1. Select **Webhooks** in the left navigation.
2. Choose Test or Live, then click **Create**. In Live, the number of webhooks you can have depends on your [Print & Mail edition](https://dashboard.lob.com/#/settings/editions). Test has no limit.
3. Enter a name in the **Description** field.
4. Enter the [URL of the server that will receive the webhook](https://help.lob.com/print-and-mail/getting-data-and-results/using-webhooks#receiving-a-webhook).
5. Set a [rate limit](https://help.lob.com/print-and-mail/getting-data-and-results/using-webhooks#webhook-rate-limits) if you need one.
6. Select an [event type](https://docs.lob.com/#all_event_types). For example, to hear when a postcard is re-routed, choose postcard.re-routed under Postcards.
7. Click **Create**.

After you create a webhook, click it to open its Details page. It shows a summary and every delivery attempt, and it's where you replay events, debug, edit or delete the webhook.

### Receiving a webhook

Create an endpoint on your server that accepts POST requests with the application/json content type. Lob needs to be able to reach it, so turn off anything that might block Lob for this endpoint. See [Security](https://help.lob.com/print-and-mail/getting-data-and-results/using-webhooks#security) below. If a firewall protects your endpoint, see [IP allowlisting](https://help.lob.com/print-and-mail/getting-data-and-results/using-webhooks#ip-allowlisting).

* **Return a 2xx right away.** Any other status, or no response, counts as an error and Lob retries. If your endpoint runs complex logic, return the 2xx first and process the event afterward, so network timeouts don't trigger retries.
* **Response bodies are saved, not read.** Lob stores whatever you return and shows it in your dashboard, but doesn't act on it. A short JSON object with debugging details works best. HTML is accepted too.
* **Events aren't guaranteed to be real time.** Lob sends each event as soon as it's available, but delays can happen. For example, a subscription to postcard.processed\_for\_delivery may also return earlier tracking events like postcard.in\_local\_area, postcard.in\_transit and postcard.mailed.

{% hint style="info" %}
For tracking events, the USPS scan time is in tracking\_events\[].time, even if the event reaches you late.
{% endhint %}

### Webhooks JSON schema

API responses for creating mail pieces aren't redacted, but webhooks redact fields that could contain personal or health information.

Redacted for every mail type: the from address, the to address, mail piece URLs, metadata, description and merge variables. For checks, the memo field and everything in the bank account property (routing number, account number, bank name and so on) are redacted too.

To see a sample redacted payload, go to **Webhooks** in the dashboard, click [**Debugger**](https://dashboard.lob.com/#/webhooks/debugger) (on the Webhooks page or a subscription page), and open the **Event Object** tab.

```
{
  "event_type": {
    "resource": "self mailers",
    "enabled_for_test": true,
    "id": "self_mailer.rendered_thumbnails",
    "object": "event_type"
  },
  "reference_id": "sfm_c29bbbca5f7bd489",
  "date_created": "2021-12-16T01:34:18.159Z",
  "id": "evt_d47ff1b815373f67",
  "body": {
    "id": "sfm_c29bbbca5f7bd489",
    "description": "self mailer create",
    "metadata": {
      "secretId": "REDACTED",
      "subObject": {
        "subId": "REDACTED"
      }
    },
    "to": {
      "id": "REDACTED",
      "description": "REDACTED",
      "name": "REDACTED",
      "company": "REDACTED",
      "phone": "REDACTED",
      "email": "REDACTED",
      "address_line1": "REDACTED",
      "address_line2": "REDACTED",
      "address_city": "REDACTED",
      "address_state": "REDACTED",
      "address_zip": "REDACTED",
      "address_country": "REDACTED",
      "metadata": {
        "arrayTest": [
          "REDACTED",
          {
            "keyInArray": "REDACTED",
            "key2": "REDACTED"
          },
          {
            "keyInArray2": "REDACTED"
          }
        ]
      },
      "date_created": "REDACTED",
      "date_modified": "REDACTED",
      "deleted": "REDACTED",
      "object": "REDACTED"
    },
    "from": {
      "id": "REDACTED",
      "description": "REDACTED",
      "name": "REDACTED",
      "company": "REDACTED",
      "phone": "REDACTED",
      "email": "REDACTED",
      "address_line1": "REDACTED",
      "address_line2": "REDACTED",
      "address_city": "REDACTED",
      "address_state": "REDACTED",
      "address_zip": "REDACTED",
      "address_country": "REDACTED",
      "metadata": {},
      "date_created": "REDACTED",
      "date_modified": "REDACTED",
      "deleted": "REDACTED",
      "object": "REDACTED"
    },
    "url": "REDACTED",
    "outside_template_id": null,
    "inside_template_id": null,
    "inside_template_version_id": null,
    "outside_template_version_id": null,
    "carrier": "USPS",
    "tracking_events": [],
    "thumbnails": [
      {
        "small": "REDACTED",
        "medium": "REDACTED",
        "large": "REDACTED"
      },
      {
        "small": "REDACTED",
        "medium": "REDACTED",
        "large": "REDACTED"
      }
    ],
    "merge_variables": "REDACTED",
    "size": "6x18_bifold",
    "mail_type": "usps_first_class",
    "expected_delivery_date": "2021-12-27",
    "target_delivery_date": null,
    "date_created": "2021-12-16T01:34:12.087Z",
    "date_modified": "2021-12-16T01:34:14.469Z",
    "send_date": "2021-12-16T01:39:12.078Z",
    "object": "self_mailer"
  },
  "object": "event"
}
```

To change redaction, go to [Settings > Account](https://dashboard.lob.com/settings/account) and find Webhooks Payload.

{% hint style="warning" %}
While this setting is Redacted, Lob can't retrieve payload information later.
{% endhint %}

### Test vs. Live environment

Events and webhooks exist in both environments. Test webhooks fire on events from your Test API key, and Live webhooks fire on events from your Live API key.

[Tracking events](https://docs.lob.com/#tag/Tracking-Events) only happen in Live, so you can't subscribe to them in Test. To debug them, send a mock event from the [Debugger](https://dashboard.lob.com/#/webhooks/debugger).

### Integration tips

* **Start with the** [**Debugger**](https://dashboard.lob.com/#/webhooks/debugger)**.** It sends a generated event to your URL whenever you want, which is the easiest way to learn the JSON structure. IDs and URLs in these events are made up and don't match real resources.
* **Developing locally?** Use a tunneling tool like [ngrok](https://ngrok.com) to expose your local server without deploying it.

### Webhook rate limits

Set a rate limit on a subscription if your server or gateway has limits, or to control how fast events arrive. Account Admins can set it when creating a webhook or by editing one on the [Webhooks page](https://dashboard.lob.com/webhooks): click Edit, enter the limit per 5-second interval, and click Update. The change takes effect immediately.

### Replaying webhooks

If something on your end causes deliveries to fail, you can replay them once it's fixed. Account Admins open the subscription on the Webhooks page, click **Replay Events**, enter a start date, and click **Replay Events** again. Every non-2xx event from that date to now is sent again.

### Retry policy

If a delivery fails (a non-2xx response, an SSL/TLS error, a DNS issue and so on), Lob retries the same event on this schedule until it gets a 2xx or runs out of attempts:

| Attempt | Time since last attempt | Time since first attempt | Example timestamp    |
| ------- | ----------------------- | ------------------------ | -------------------- |
| 1       | Immediately             | 0 min                    | 2022-01-01T00:00:00Z |
| 2       | 5 sec                   | 5 sec                    | 2022-01-01T00:00:05Z |
| 3       | 5 min                   | \~5 min                  | 2022-01-01T00:05:05Z |
| 4       | 30 min                  | \~35 min                 | 2022-01-01T00:35:05Z |
| 5       | 2 hr                    | \~2 hr 35 min            | 2022-01-01T02:35:05Z |
| 6       | 5 hr                    | \~7 hr 35 min            | 2022-01-01T07:35:05Z |
| 7       | 10 hr                   | \~17 hr 35 min           | 2022-01-01T17:35:05Z |
| 8       | 10 hr                   | \~27 hr 35 min           | 2022-01-02T03:35:05Z |

After the 8th attempt, Lob stops retrying that event.

### Disabling policy

If an endpoint keeps failing, Lob turns the webhook off after 5 consecutive days of failures and stops sending it events. The clock starts at the first failure, and one successful delivery resets it. You'll get an email when a webhook is disabled. To turn it back on, edit the webhook on the [Webhooks page](https://dashboard.lob.com/#/webhooks).

### Security

Lob needs to reach your endpoint without opening it up to bad actors. These features help.

#### TLS

Lob requires HTTPS for every webhook URL, so data is encrypted in transit. Use a fully chained certificate. Without one, requests never reach your server and fail. Send a test from the Debugger to confirm requests get through.

#### Webhook signatures

Every webhook includes Lob-Signature and Lob-Signature-Timestamp headers. Checking them confirms the request came from Lob.

Lob-Signature is an HMAC-SHA256 of the timestamp (as a string), a period, and the raw JSON payload (as a string), keyed with the webhook's secret. You'll find each webhook's secret on its Details page.

{% hint style="warning" %}
Events sent from the [Debugger](https://dashboard.lob.com/#/webhooks/debugger) are signed with the word "secret," not your webhook's secret. Use "secret" as the key when validating them.
{% endhint %}

The timestamp protects against replay attacks. Reject requests with a timestamp outside your tolerance. We recommend 5 minutes.

To verify a webhook:

1. Build the signature input: the timestamp, a period, and the raw request body exactly as received. Don't re-serialize the body.
2. Compute an HMAC-SHA256 using your webhook's secret as the key and the signature input as the message, and encode it as a hex string.
3. Compare the result to the Lob-Signature header. If they match, the webhook is valid.
4. Optional: check that Lob-Signature-Timestamp is within your tolerance.

#### IP allowlisting

<img src="https://1775164782-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiXDYGxBp6aAwhpEhTMNC%2Fuploads%2FPowT0cnISB3CEhbg0c9j%2FPasted%20image%202026-11-19%2023.39.48.png?alt=media&amp;token=76af6806-c693-4cdc-b9fa-0b882feda85f" alt="" height="276" width="624">

If a firewall or web application firewall protects your endpoint, it may block Lob's requests before they reach you. Allow inbound requests from these addresses:

* 44.228.126.217
* 50.112.21.217
* 52.24.126.164
* 54.148.139.208
* 2600:1f24:64:8000::/56

Don't rely on IP addresses alone. Keep verifying the Lob-Signature header on every request, as described in [Webhook signatures](https://help.lob.com/print-and-mail/getting-data-and-results/using-webhooks#webhook-signatures).

While requests are blocked, each delivery counts as a failure, so Lob retries and eventually disables the webhook. Once you've updated your allowlist, [re-enable the webhook if needed](https://help.lob.com/print-and-mail/getting-data-and-results/using-webhooks#disabling-policy), then use [**Replay Events**](https://help.lob.com/print-and-mail/getting-data-and-results/using-webhooks#replaying-webhooks) to resend what you missed.

#### Basic authentication

You can also protect your endpoint with HTTP Basic Authentication, alongside or instead of signatures. We recommend signatures over Basic Auth alone. Put the credentials in the webhook URL, like <https://username:password@example.com/webhooks>, and Lob sends them as an Authorization header.

#### CSRF

Some frameworks turn on [CSRF protection](https://owasp.org/index.php/CSRF) by default, which can block Lob's events. Don't turn it off everywhere. Exempt only your webhook endpoint.

### API versions

Events use the [API version](https://dashboard.lob.com/#/settings/keys) set on your account when the event is created, even if your request [hard-codes a different version header](https://docs.lob.com/#version). Upgrading your [API version](https://dashboard.lob.com/#/settings/keys) doesn't change past events. Only new events use the new structure.

### Return envelope tracking

Enterprise edition customers using USPS Courtesy Reply Mail [return envelopes](https://help.lob.com/print-and-mail/designing-mail/mail-piece-design-specs/letter-envelopes#return-envelope-tracking-4) (letters only) get tracking events for them by webhook once USPS scans the envelope:

* **Created:** The envelope was created, at the same time as the letter.
* **In transit:** Being processed at the origin facility.
* **In local area:** Being processed at the destination facility.
* **Processed for delivery:** Cleared for delivery at the recipient's nearest postal facility. It should arrive within 1 business day.
* **Re-routed:** Sent elsewhere because of an address change, an address error, or USPS relabeling the barcode or ID tag area.
* **Returned to sender:** Undeliverable because of a barcode, ID tag or address error.

These events are only available by webhook and in the dashboard's Event Logs. They show up in the Letters Events section of the original mail piece as soon as they're available, and you can export them with Export at the top of the Letters section.

#### View tracking events for return envelopes

1. Log in to [dashboard.lob.com](https://dashboard.lob.com).
2. Go to API **Requests > Event Logs**.
3. Click **Filters** at the top left, select **Letters** under Resources, select the event types that start with letter.return\_envelope, and click **Apply**.
4. Select an event to see details about its mail piece.
