Lemon Squeezy uses webhooks to notify your application when an event happens in your store. Webhooks are particularly useful for asynchronous events like when a license key is created or when a subscription expires.
Webhooks can be set up in your store settings panel. Webhooks require three elements to function:
- A callback URL - This is the URL that Lemon Squeezy will send a
POSTrequest to when an event is triggered.
- A signing secret - This is a secret (usually a random string) that will be used to sign each request so that your application can validate that the request came from Lemon Squeezy.
- A list of events - This is a list of events that will trigger this webhook.
Lemon Squeezy supports passing custom data through the checkout that can be captured using webhooks. See this doc for more information.
Note that webhooks are live and test mode specific. A test mode webhook will only be triggered for test mode data and vice versa.
When a webhook event occurs in Lemon Squeezy, a
POST request will be sent to the configured webhook URL. If the response status is
200 then the webhook will consider the request successfully sent. If the response status is anything else, the webhook will be retried up to three more times using an exponential backoff strategy (e.g. 5 secs, 25 secs, 125 secs) at which point the request will be considered failed and will no longer be retried.
The webhook body will be a JSON:API resource object that relates to the event (e.g. “order” events will be sent an order object, “subscription” events will be sent a subscription object, etc). The request headers will include:
Content-Typeheader set to
X-Event-Nameheader with the name of the event that triggered the webhook.
X-Signatureheader containing the request signature.
If a webhook is configured to send a request to an HTTPS URL, the SSL certificate of the URL will be verified before sending the request.
To ensure that webhook requests are coming from Lemon Squeezy, you will be asked to enter a signing secret when creating your webhook. The secret can be anything you want but is normally a random string between 6 and 40 characters in length.
When the webhook request is sent, Lemon Squeezy will use the signing secret to generate a hash of the payload and send the hash in the
X-Signature header of the request. You can use the same secret to calculate the hash in your application and check it against the request signature to verify that the hashes match.
Lemon Squeezy uses a HMAC hex digest to compute the hash. Calculating the hash is different in each programming language.