> ## Documentation Index
> Fetch the complete documentation index at: https://docs.postsyncer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Test webhooks locally

> Get PostSyncer webhook events on your own machine while you build your handler

PostSyncer sends webhooks only to public `https` addresses. `localhost`, private and loopback addresses are refused when you save the endpoint, and again each time PostSyncer sends. To get events on a server running on your machine, put a tunnel in front of it.

## Run your handler

Start your server on a local port, for example `3000`, with a route such as `/webhooks/postsyncer`. The route should:

1. Read the raw body before parsing it, and check the signature. [Verify webhook signatures](https://docs.postsyncer.com/guides/verify-webhooks.md) has the code.
2. Answer with a `2xx` status within 10 seconds, and do slow work after that.
3. Skip an event whose `id` it has already handled. Retries send the same `id`.

## Open a tunnel

A tunnel gives your local port a public `https` address. Any tunnel works, for example ngrok or Cloudflare Tunnel:

```bash ngrok theme={null}
ngrok http 3000
```

```bash Cloudflare Tunnel theme={null}
cloudflared tunnel --url http://localhost:3000
```

Copy the `https` address it prints. The examples below call it `https://YOUR_TUNNEL_HOST`.

The address must answer the request itself. PostSyncer doesn't follow redirects, so a `3xx` answer counts as a failure.

## Create an endpoint

Point a new endpoint at the tunnel. Listen to `webhook.test` and the events you are building for:

```bash theme={null}
curl -X POST "https://postsyncer.com/api/v1/webhooks" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "workspace_id": 12,
    "name": "Local test",
    "url": "https://YOUR_TUNNEL_HOST/webhooks/postsyncer",
    "events": ["webhook.test", "post.published", "post.failed"]
  }'
```

The answer has the endpoint's `id` and its signing `secret`, which starts with `whsec_`. The API shows the secret this once, so save it where your handler reads it. You need `webhooks:create`, and to be the workspace's owner or a manager. See [Create a webhook](https://docs.postsyncer.com/api-reference/webhooks/create.md).

If the tunnel's address changes when you start it again, change the endpoint's `url` with [Update a webhook](https://docs.postsyncer.com/api-reference/webhooks/update.md). Delete the endpoint when you're done, so it doesn't fail for 3 days and get turned off.

## Send a test event

```bash theme={null}
curl -X POST "https://postsyncer.com/api/v1/webhooks/42/test" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

PostSyncer sends a signed `webhook.test` event to this one endpoint and answers with the delivery, `pending` at first. It needs `webhooks:update`. Over MCP, the `test-webhook` tool does the same, and the app has a test button on each endpoint. See [Send a test event](https://docs.postsyncer.com/api-reference/webhooks/test.md).

A test sent to an endpoint that is off isn't sent: its delivery fails with `The destination is off.`

## See what happened

Each delivery keeps the request PostSyncer sent and what your server answered:

```bash theme={null}
curl "https://postsyncer.com/api/v1/webhooks/42/deliveries" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

Deliveries come newest first, 25 to a page. Add `?status=failed` to see only the failed ones, including those that gave up. It needs `webhooks:read`, and the `list-webhook-deliveries` tool does the same. See [List webhook deliveries](https://docs.postsyncer.com/api-reference/webhooks/deliveries.md).

| Field | What to look for |
| - | - |
| `status` | `pending` (waiting for its first try or a retry), `sent`, `failed` (won't be tried again) or `gave_up` (out of retries) |
| `attempts` | How many times it was tried |
| `response_status` | The status your server answered, or `null` when no answer came |
| `response_body` | The start of your server's answer, up to 1000 characters |
| `error` | What went wrong, in words, such as `Your server didn’t answer within 10 seconds.` |
| `next_attempt_at` | When the next retry is due, for a delivery waiting for one |
| `request_headers`, `request_body` | What PostSyncer sent. `request_body` keeps the first 64 KB. |

To replay a stored request against your handler, sign it again with the script below. The stored signature is older than the 5 minutes a handler accepts, and a body cut at 64 KB no longer matches it.

In the app, **Send again** sends a failed delivery once more, while the endpoint is on.

## Send a signed request yourself

You can also test your handler without PostSyncer, by signing a body with your endpoint's secret the way PostSyncer does. This script sends the test event to your local server:

```python theme={null}
import base64, hashlib, hmac, json, os, time, urllib.request

secret = os.environ["POSTSYNCER_WEBHOOK_SECRET"]  # whsec_...
event_id = "01q9aa9wn8k5r6t1n0xwdq7h3m"
body = json.dumps({
    "type": "webhook.test",
    "id": event_id,
    "timestamp": "2030-03-15T09:00:41+00:00",
    "workspace_id": 12,
    "data": {"message": "This is a test event from PostSyncer."},
})

timestamp = str(int(time.time()))
key = base64.b64decode(secret.removeprefix("whsec_"))
digest = hmac.new(key, f"{event_id}.{timestamp}.{body}".encode(), hashlib.sha256).digest()

request = urllib.request.Request(
    "http://localhost:3000/webhooks/postsyncer",
    data=body.encode(),
    headers={
        "content-type": "application/json",
        "webhook-id": event_id,
        "webhook-timestamp": timestamp,
        "webhook-signature": "v1," + base64.b64encode(digest).decode(),
    },
)
print(urllib.request.urlopen(request).status)
```

Swap `body` for any example on [Webhook events](https://docs.postsyncer.com/webhooks/events.md) to try that event. Your handler should accept this request, refuse it after you change one character of the body, and refuse it again when `webhook-timestamp` is more than 5 minutes old.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.