---
title: "Fix failed deliveries"
description: "Find the EventWolf webhook deliveries that failed, read why from their attempts, fix the cause, and send each one again with a retry."
url: "https://agentpost.tools/docs/eventwolf/guides/failed-deliveries"
kind: guide
needs:
  - what: "The `api` helper"
    from: "https://agentpost.tools/docs/platform/quickstart.md"
  - what: "A `dev` secret key, `key`, for a project that adopted EventWolf"
    from: "https://agentpost.tools/docs/platform/guides/keys.md"
---

# Fix failed deliveries

Use this guide when a receiver missed webhooks after a failed attempt. A retry sends the same delivery again, with the same `webhook-id`. To send events for which EventWolf created no delivery, such as those accepted while a subscription was paused, [replay them](/docs/eventwolf/guides/replays.md). [Deliveries](/docs/eventwolf/concepts/deliveries.md) explains attempts, retries, and statuses.

## Before you start

-   The `api` helper, from [Platform quickstart](/docs/platform/quickstart.md).
-   A `dev` secret key, `key`, for a project that adopted EventWolf, from [Create a project and issue a key](/docs/platform/guides/keys.md).

This page's code continues the script of the pages above: run its blocks after theirs, in the same file. To run them as a script of their own, first copy each helper from the page that defines it, and set each other value, such as a key or an ID, to one you already have.

## 1\. Find the failing deliveries

A delivery waiting for a retry is `pending`. A delivery that ran out of retries, or whose receiver answered `410`, is `failed`. List both webhook statuses and keep the deliveries whose attempts have started:

```ts
const failing = [];
for (const status of ['failed', 'pending']) {
  const { deliveries } = await api(
    'GET',
    `/v1/events/deliveries?kind=webhook&status=${status}&limit=200`,
    key,
  );
  failing.push(...deliveries.filter((delivery) => delivery.attempts > 0));
}
console.log(failing.length, failing[0].status); // 1 pending
```

`attempts` counts every attempt so far, EventWolf’s own retries included. Agentpost’s starting schedule retries 5 seconds after the first failure.

An endpoint’s test is a delivery too, with no `subscriptionId`. Add `endpointId` or `subscriptionId` to narrow the results. While an answer has `next`, send it as `after` with the same filters for the next page.

To [list deliveries](/docs/eventwolf/reference/deliveries.md#list-deliveries) for one event, send its `sequence` as `eventSequence`. Get the sequence from the publish result or [look up the event](/docs/eventwolf/reference/events.md#look-up-an-event) by `source` and `id`.

## 2\. Read why it failed

Get the delivery with its attempts. The last recorded attempt holds the receiver’s answer, or why there was none. A delivery’s `attempts` counts an attempt from when it starts, and the attempt’s record appears when it ends. Wait until the delivery has a record for each attempt before you read the last one.

```ts
let { delivery, attempts } = await api(
  'GET',
  `/v1/events/deliveries/${failing[0].id}`,
  key,
);
for (
  let wait = 0;
  wait < 30 && attempts.length < delivery.attempts;
  wait += 1
) {
  await new Promise((resolve) => setTimeout(resolve, 1000));
  ({ delivery, attempts } = await api(
    'GET',
    `/v1/events/deliveries/${failing[0].id}`,
    key,
  ));
}
const last = attempts.at(-1);
console.log(
  last.response?.status ?? last.error?.code,
  last.response?.bodyExcerpt,
);
// 503 upstream unavailable
```

`delivery.nextAttemptAt` is when EventWolf tries again by itself.

## 3\. Fix the cause

Find what the last attempt shows, and fix it before you send the delivery again:

| The last attempt shows | What to fix |
| --- | --- |
| `response.status` 5xx | The receiver failed. `response.bodyExcerpt` holds the first 2 KB of its answer; fix the receiver. |
| `response.status` 429 or 503 | The receiver was busy. EventWolf already waits as its `Retry-After` asks, up to a day, until `nextAttemptAt`, so a retry may not be needed. |
| `response.status` 401 or 403 | The receiver refused the request: check that it verifies with the endpoint’s current secret, and the endpoint’s static headers. |
| `response.status` 404 or 405 | The URL is wrong. [Update the endpoint](/docs/eventwolf/reference/endpoints.md#update-an-endpoint) with the right `url`. |
| `response.status` 410 | Fix the receiver or its URL and [enable the endpoint](/docs/eventwolf/reference/endpoints.md#enable-an-endpoint). Retry the failed delivery, or [recover failed and skipped deliveries](/docs/eventwolf/reference/endpoints.md#recover-failed-deliveries) with `since` set to when the earliest of them was created. |
| `error.code` `dns`, `connection`, `tls` | EventWolf couldn’t reach the receiver: check the URL’s hostname, that the server is up, and its certificate. |
| `error.code` `timeout` | The receiver took longer than the config’s `delivery.timeout`, `"15s"` in Agentpost’s starting config. Answer `2xx` first, then do slow work. |
| `error.code` `redirect` | The receiver answered `3xx`, which isn’t followed. Update the endpoint with the final URL. |
| `error.code` `ssrf_blocked` | The URL resolves to a private or reserved address. Use a public address. |

## 4\. Retry the delivery

Once the receiver works, retry the delivery to put it back in the queue for an immediate attempt. A scheduled retry can increase `attempts` while you look. A retry answers `conflict` while an attempt is in progress or once the delivery has succeeded:

```ts
const retried = await api(
  'POST',
  `/v1/events/deliveries/${delivery.id}/retry`,
  key,
);
console.log(retried.delivery.status); // pending
```

A delivery that succeeded answers [`conflict`](/docs/eventwolf/errors.md#conflict): replay its event to send it again. When many deliveries of one endpoint failed, such as during an outage, [recover them](/docs/eventwolf/reference/endpoints.md#recover-failed-deliveries) in one request instead.

## Check it worked

Read the delivery until it leaves `pending`:

```ts
let after = retried.delivery;
for (let wait = 0; wait < 30 && after.status === 'pending'; wait += 1) {
  await new Promise((resolve) => setTimeout(resolve, 1000));
  ({ delivery: after } = await api(
    'GET',
    `/v1/events/deliveries/${delivery.id}`,
    key,
  ));
}
console.log(after.status); // succeeded
```

If the retry fails, go back to step 2. A delivery still `pending` after this check can be waiting for its attempt or its next retry. Read its last recorded attempt and `nextAttemptAt`.
