---
title: "Hear every step by webhook"
description: "Learn how to register a webhook that posts each step of your invoices to your own system."
---

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

# Hear every step by webhook

A webhook lets your system hear what happens to its invoices without asking. Each step added to an
invoice's history is posted to your URL: received, checked, the verdict, downloaded, sent, paid. This guide
shows how to register a webhook, check its signature, handle failures, and forward an invoice file.

## Register a URL

```bash
curl -s -X POST -H "Authorization: Bearer cvo_live_sk_..." -H "content-type: application/json" \
  -d '{"url": "https://erp.example.com/certinvo", "events": ["kosit:clean", "kosit:rejected"]}' \
  "https://<api-host>/v1/webhooks"
```

`events` lists the history codes to hear. Leave it out to hear every step.

The answer holds the webhook's `id` and its signing `secret`, `whsec_...`. **The secret is shown once.** If
you lose it, stop the webhook and register the URL again.

The API refuses a webhook with 400 in these cases:

| Code | Cause |
| --- | --- |
| `invalid_webhook_url` | The URL is not https to a public host. A local or private address is refused. |
| `invalid_webhook_events` | A code is not in the history's list, the list is empty, or a code is named twice. |
| `too_many_webhooks` | The company already has 10 live webhooks. |

A host name is checked again each time a step is posted. If it now resolves to a local or private address,
the post is refused.

## Manage webhooks

- `GET /v1/webhooks` lists the live webhooks, without their secrets.
- `PATCH /v1/webhooks/{id}` with `{"events": [...]}` or `{"events": null}` changes the steps it hears. Steps
  already waiting are posted as they were.
- `DELETE /v1/webhooks/{id}` stops a webhook. Nothing more is posted to it, including steps still waiting
  for another attempt.

### In the console

Open **Webhooks** in the rail. **Settings**, then **Connections**, then **Webhooks** links to the same page. From
there you can:

- see the live webhooks and the steps each hears;
- register a URL with its steps from **Register webhook** at the top right, and see its secret once;
- stop a webhook, after a second click to confirm;
- press **Test** to post one test step and see what your endpoint answered;
- open **Steps and deliveries** to change the steps and see the last deliveries under the list, with
  **Send again** on a settled one. Each delivery's state sits last in its row. **Download** beside **Refresh** saves
  every delivery, not only the last 50, as CSV, Excel or JSON.

The screen also shows a curl call that registers a webhook, and the signature check below. When the API
refuses an action, the screen says why in the console's language, chosen by the refusal's code. When a test
or a delivery got no answer from your endpoint, the error the server met is shown as it is, in English, marked
"The server said, in English: …". 

## What arrives

Each step is one POST with a JSON body:

```json
{ "type": "kosit:clean", "invoiceId": "...", "event": { "id": "42", "statusCode": "kosit:clean", "createdAt": "..." } }
```

`event` is the step exactly as `GET /v1/invoices/{id}/events` returns it. A step can arrive twice, and steps
can arrive out of order. Use `event.id` to recognise a step you already have.

## Check the signature

Each POST is signed as [Standard Webhooks](https://www.standardwebhooks.com) specifies. Its library checks
the signature in your language, with no code of your own. Three headers carry it:

| Header | What it holds |
| --- | --- |
| `webhook-id` | `msg_` and the delivery's id. It is the same on every attempt of one delivery. |
| `webhook-timestamp` | Unix seconds when this attempt was signed. |
| `webhook-signature` | `v1,` and the base64 HMAC SHA-256 of `<webhook-id>.<webhook-timestamp>.<body>`, keyed with the bytes of the secret after `whsec_`, read as base64. |

```ts
import { Webhook } from 'standardwebhooks'

const event = new Webhook(secret).verify(rawBody, headers) // throws when the signature or the time is wrong
```

The library also refuses a timestamp more than five minutes old.

## Test an endpoint

`POST /v1/webhooks/{id}/test` posts one signed `{"type": "webhook.test", "invoiceId": null, "event": null}`
right away. It answers with what your endpoint said, such as `{"status": 200, "error": null}`. When no answer
came, `status` is null and `error` says why.

A test is not retried and is not listed among the deliveries.

## When the receiver fails

A delivery fails when your endpoint answers anything other than 2xx, or does not answer within 10 seconds.
Certinvo then tries again 1, 4, 16, 64 and 256 minutes later. After the sixth failed attempt, that step is
not posted again. The step itself stays in the invoice's history.

`GET /v1/webhooks/{id}/deliveries` lists the newest 50 deliveries. Each shows its step, state (`pending`,
`delivered`, `failed`), attempts and your endpoint's last answer. `GET /v1/data-files/webhook-deliveries?webhook={id}` downloads
all of them as a CSV, Excel or JSON file ([Download lists as files](/how-to/invoices/download-lists-as-files)).

`POST /v1/webhooks/{id}/deliveries/{deliveryId}/resend` starts a fresh round of six attempts for one
delivery. The first attempt is now, with the same `webhook-id`.

## Forward an invoice to your own system

`POST /v1/invoices/{id}/forwards` with `{"format": "ubl"}` adds the step `api:forwarded` to the invoice's
history. Webhooks that hear that step receive it with `event.data` set to
`{"format": "ubl", "href": "/v1/invoices/{id}/download?format=ubl"}`.

Your system fetches the file from `href` with its API key. The file is not in the post.

The file is announced only when the invoice's newest check accepts it. For example, a rejected invoice is
refused with 409 `invoice_rejected`. An invoice already sent stays downloadable on the check it was sent with,
but forwarding it again needs the newest check. When no live webhook hears `api:forwarded`, nothing is added and the answer is
409 `no_webhook_for_forwards`. A received invoice your settings hold for its bank account is not announced until a
person releases it: 409 `invoice_on_hold`.

Send an `Idempotency-Key` header to forward once. A retry with the same key and body answers the first step, so
your system hears it once. The same key with another body is 409 `idempotency_key_reused`, and while the first is
still being done it is 409 `request_in_progress`. Without a key, every request adds a step.

In the console, this is **ERP-Webhook** in the queue's **Versenden** menu. Each press sends an `Idempotency-Key`. A
press again after no answer, or after a refusal, carries the same key. Once a forward succeeded, the next press is a
new forward.

## Who may

Adding or changing a webhook needs an owner, an admin or a developer. Anyone else gets 403 `role_required`. 

## See also

- [Send and receive invoices by SFTP](/how-to/invoices/send-and-receive-invoices-by-sftp)
- [Send an invoice by email](/how-to/invoices/send-an-invoice-by-email)
- [API error codes](/reference/api-error-codes)

Source: https://docs.certinvo.com/how-to/invoices/hear-every-step-by-webhook/index.mdx
