Webhooks
Lid notifies your backend when a sale settles, a conversion is approved, or a prize is claimed. Verify every delivery before trusting it.
Verify a delivery
Lid signs every delivery with HMAC-SHA256 over timestamp + '.' + rawBody and sends the result in three headers. constructWebhookEvent verifies the signature, rejects deliveries older than 5 minutes, and returns the event typed by its name.
x-lid-eventx-lid-timestampx-lid-signature
// app/api/lid/route.ts
import { constructWebhookEvent, LidWebhookError } from '@lidpro/sdk/webhooks';
export async function POST(request: Request) {
const rawBody = await request.text(); // the raw text, never request.json()
try {
const event = await constructWebhookEvent({
secret: process.env.LID_WEBHOOK_SECRET!,
rawBody,
headers: request.headers,
});
switch (event.event) {
case 'purchase.completed':
// event.id repeats on a retried delivery: make fulfil skip an id it has seen
await fulfil(event.id, event.data.productId, event.data.buyer);
break;
case 'prize.claimed':
await notify(event.data.winner, event.data.amount);
break;
}
return new Response('ok');
} catch (e) {
if (e instanceof LidWebhookError) {
// Signed by Lid, only newer than this SDK: acknowledge it so the endpoint stays on.
if (e.reason === 'unknown_event') return new Response('ignored');
return new Response(e.reason, { status: 400 });
}
throw e;
}
}A valid signature does not mean a new event: Lid retries a failed delivery with the same id, and your endpoint may time out after doing the work. Store event.id next to the fulfilment and skip an id you already processed, in the same transaction, so a replay never delivers twice.
Events
Subscribe to any subset when you create the endpoint. webhook.test is not subscribable: every endpoint can receive it from the test button.
| Event | What it does |
|---|---|
purchase.completed | Sent to the creator when a sale of one of their products settles on Solana. |
conversion.approved | Sent to the sharer when one of their campaign conversions is approved, automatically or by the owner. |
prize.claimed | Sent to the recipient when they claim a prize from a pool. |
subscription.created | Sent to the creator on the first payment of a membership; renewals do not send it. |
bounty.submission.created | Sent to the creator of a challenge when someone submits an entry. |
webhook.test | Synthetic delivery sent by the test button, to check that your endpoint answers. |
Rejected deliveries
constructWebhookEvent throws a LidWebhookError with one of these reasons. Answer unknown_event with a 2xx: the signature checked out and the event is only newer than your SDK. Answer the rest with a 4xx. Lid counts any status other than 2xx as a failed delivery and turns the endpoint off after 20 in a row.
| Reason | What it does |
|---|---|
format | A required header is missing or unparsable. |
timestamp | The delivery is older than the 5-minute tolerance. |
signature | The signature does not match the body. |
event | The x-lid-event header disagrees with the body. |
payload | The body is not JSON, or does not match the event's shape. |
unknown_event | A genuine event your version of the SDK does not know yet (eventName has its name). Acknowledge it with a 2xx. |
Test locally
Do not wait for a sale to test your handler. signWebhookPayload is the same HMAC the verifier checks: sign a body with your endpoint secret, send it with the three headers, and your route runs exactly as it will in production. The test button on the endpoint does the same from Lid's side.
import { signWebhookPayload } from '@lidpro/sdk/webhooks';
const timestamp = Math.floor(Date.now() / 1000); // unix seconds, a number in the body
const rawBody = JSON.stringify({
id: 'evt_test',
event: 'webhook.test',
timestamp,
data: { message: 'hello', endpointId: 'whk_local', ts: new Date().toISOString() },
});
const signature = await signWebhookPayload(secret, timestamp, rawBody);
await fetch('http://localhost:3000/api/lid', {
method: 'POST',
headers: {
'content-type': 'application/json',
'x-lid-event': 'webhook.test',
'x-lid-timestamp': String(timestamp),
'x-lid-signature': signature,
},
body: rawBody,
});Manage endpoints
Create, list, test and delete endpoints from the REST API or the MCP agent; the signing secret is shown once, when you create the endpoint. To change it, create a new endpoint and delete the old one.