# Testing and the delivery log

Send a test event, see what was delivered and why something failed, and send it again.

## Send a test event

[Send a test event](https://chatwise.so/docs/api/test-webhook-endpoint.md) from the dashboard or with the API. Chatwise sends a signed [`webhook.test`](https://chatwise.so/docs/webhooks/events/webhook-test.md) event right away and tells you what your endpoint did:

```bash
curl -X POST 'https://api.chatwise.so/v1/webhook-endpoints/we_01JE2Z3K8Q9V7W5X4Y3Z2A1B0C/test' \
  -H "Authorization: Bearer $CHATWISE_API_KEY"
```

```json
{
  "data": {
    "delivered": false,
    "statusCode": 400,
    "durationMs": 96,
    "error": "http_400"
  }
}
```

- The request itself answers 200, also when your endpoint failed. Look at `delivered`.
- `statusCode` is `null` when there was no answer, and `error` says why.
- It works while the endpoint is paused, and needs no subscription.
- A test isn't retried and isn't in the delivery log.

## Test without Chatwise

The [OpenAPI file](https://chatwise.so/docs/openapi.json) has two signed deliveries under `x-webhook-signing-examples`, with their secret, headers and exact body. Your verification should accept both when you pass their timestamp as the current time, and refuse them when you change one character of the body.

## Read the delivery log

The log has one delivery for each event and endpoint, newest first. [List deliveries](https://chatwise.so/docs/api/list-webhook-deliveries.md) filters by `status` and `eventType`:

```bash
curl 'https://api.chatwise.so/v1/webhook-endpoints/we_01JE2Z3K8Q9V7W5X4Y3Z2A1B0C/deliveries?status=FAILED' \
  -H "Authorization: Bearer $CHATWISE_API_KEY"
```

| Status | What it means |
| --- | --- |
| `PENDING` | Waiting to be sent. |
| `PROCESSING` | Being sent now. |
| `RETRY` | The last attempt failed. `nextAttemptAt` says when the next one is due. |
| `DELIVERED` | Your endpoint answered with a 2xx status. |
| `FAILED` | It won't be sent again by itself. `lastError` says why. |
| `CANCELLED` | The endpoint stopped subscribing to the event before it was delivered. An attempt that was under way may have arrived. |

[Get a delivery](https://chatwise.so/docs/api/get-webhook-delivery.md) adds its payload and its attempts. A success on the first try has no entry in `attemptLog`. Its time and status are on the delivery. After a redelivery the attempt numbers start again and the earlier attempts stay, so sort them by `startedAt`.

## Why a delivery failed

| `lastError` | What happened | Retried |
| --- | --- | --- |
| `http_408`, `http_425`, `http_429`, `http_5xx` | Your endpoint answered with that status. | Yes |
| `timeout` | No answer within 10 seconds. | Yes |
| `network` | Chatwise couldn't connect, or the connection broke. | Yes |
| `delivery_error` | Something failed in Chatwise. | Yes |
| `http_410` | Your endpoint answered 410 Gone. Chatwise disabled it. | No |
| `http_3xx`, other `http_4xx` | Your endpoint answered with that status. Redirects aren't followed. | No |
| `invalid_url` | The URL can't be used. | No |
| `private_address` | The URL's name leads to a private address. | No |
| `payload_too_large` | The event is larger than 256 KiB. | No |
| `message_removed` | The message was unsent, deleted or hidden before it was sent. | No |
| `retry_exhausted` | All 8 attempts failed. It takes the place of the last attempt's own error. | No |

`http_5xx` stands for the actual status, such as `http_503`.

## Redeliver

[Redeliver](https://chatwise.so/docs/api/redeliver-webhook-delivery.md) sends a delivery again, with the same event id and from its first attempt, with all its retries. Do it after you fixed your endpoint:

```bash
curl -X POST 'https://api.chatwise.so/v1/webhook-deliveries/wd_3f1c0a9b5d7e42688c1f0e2d4b6a8c90/redeliver' \
  -H "Authorization: Bearer $CHATWISE_API_KEY"
```

You can redeliver what was delivered, failed, was cancelled or is waiting for a retry, for 30 days. While the endpoint is paused or disabled, it waits. It is refused with a 400 when:

- the delivery is already waiting or being sent;
- the endpoint no longer subscribes to the event;
- the message was unsent, deleted or hidden.

A receiver that dedupes on `webhook-id` skips a redelivery of an event it already handled.
