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__
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
jwtorhmacreceive it in theX-Lago-Unique-KeyHTTP header; - endpoints signed with
standard_webhooksreceive it in thewebhook-idHTTP header, in place ofX-Lago-Unique-Key.
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:jwtandhmacsend theX-Lago-SignatureandX-Lago-Signature-AlgorithmHTTP headers. To verify the signature, decode it and compare the result with the body of the webhook.jwtis the default.standard_webhooksfollows the Standard Webhooks specification. It sends thewebhook-id,webhook-timestampandwebhook-signatureHTTP headers, and you verify them with an off-the-shelf Standard Webhooks library. See Standard Webhooks signature.
/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
2. Decode and validate the signature
HMAC signature
Decode and validate the signature
Standard Webhooks signature
Withstandard_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.- Dashboard
- API
Go to Developers > Webhooks, open the webhook endpoint, then reveal and copy its signing key.
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 whosewebhook-timestamp is more than 5 minutes away from the current time, which protects you from replayed
messages.
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 samewebhook-signature. A fixed timestamp is too old for verify, so the check uses the sign method of the
library.
Body