Skip to main content
The messages are sent as a POST request to every webhook endpoint defined in the settings of your Lago organization. If you return an error (any response other than a 2xx) or if there is a network issue, the message is sent again. Lago attempts each message 3 times, waiting longer between each attempt.

Message format

POST __WEBHOOK_URL__
The object_type field names the key that carries the object. For example, an invoice.created message has "object_type": "invoice" and an invoice key.

Unique key

Lago sends an idempotency key (a unique identifier) with each message. Use it to process a message only once:
  • endpoints signed with jwt or hmac receive it in the X-Lago-Unique-Key HTTP header;
  • endpoints signed with standard_webhooks receive it in the webhook-id HTTP header, in place of X-Lago-Unique-Key.
The key stays the same when Lago sends a message again, so you can drop a message whose key you have already processed.

Signature

Each message carries a signature. It ensures the message comes from Lago and has not been altered. You choose the signature algorithm when you create a webhook endpoint:
  • jwt and hmac send the X-Lago-Signature and X-Lago-Signature-Algorithm HTTP headers. To verify the signature, decode it and compare the result with the body of the webhook. jwt is the default.
  • standard_webhooks follows the Standard Webhooks specification. It sends the webhook-id, webhook-timestamp and webhook-signature HTTP headers, and you verify them with an off-the-shelf Standard Webhooks library. See Standard Webhooks signature.
Webhook endpoints of the v2 API (/api/v2/webhook_endpoints) only offer standard_webhooks, which is their default. Existing jwt and hmac endpoints keep working as they do today.

JWT signature

1. Retrieve the public key


You should persist the public key on your side to avoid querying it for each webhook.

2. Decode and validate the signature

HMAC signature

Decode and validate the signature

Standard Webhooks signature

With standard_webhooks, each webhook endpoint has its own signing key, a secret that starts with whsec_. Lago signs every message with it and sends three HTTP headers:
  • webhook-id: the unique key of the message. It stays the same when the message is sent again.
  • webhook-timestamp: when the message was sent, in Unix seconds.
  • webhook-signature: v1, followed by the Base64 HMAC-SHA256 signature of <webhook-id>.<webhook-timestamp>.<body>, made with the signing key.

1. Get the signing key

Only an API key with write access to webhook endpoints, or a user whose role can manage developer keys (the Admin role, or a custom role with that permission), can read the signing key. Other callers get no key.
Go to Developers > Webhooks, open the webhook endpoint, then reveal and copy its signing key.
Store the signing key on your side, like any other secret, to avoid querying it for each webhook.

2. Verify the message

Use the Standard Webhooks library of your language (Python, JavaScript, Ruby, Go, PHP, Java and Kotlin, C#, Rust). Pass it the raw request body, exactly as received: a body parsed and serialized again does not match the signature. The libraries also refuse a message whose webhook-timestamp is more than 5 minutes away from the current time, which protects you from replayed messages.
To drop a message you have already processed, store its webhook-id and skip a message whose webhook-id you already have.

3. Test your setup with a sample message

This message was signed with a test key. Signing it again with your library must give the same webhook-signature. A fixed timestamp is too old for verify, so the check uses the sign method of the library.
Body