Self-host & build › Self-hosting › Webhooks
Webhooks
Have Looona call your own server before or after a change, to log it, or to refuse it.
On your own server, Looona can call an address of yours each time something changes: a response comes in, a form is published, someone joins the team. Your server can keep a record of it, or refuse it before it happens, to set a quota or an allowlist without changing Looona.
Webhooks are for your own server only. They aren't offered on looona.com.
Turn them on
Add three lines to Looona's .env file, then restart Looona. See Server settings.
LOOONA_WEBHOOK_URL=https://hooks.example.com/looona
LOOONA_WEBHOOK_SECRET=a-long-random-secret
LOOONA_WEBHOOK_EVENTS=AFTER_CREATE_REPORT,BEFORE_CREATE_USER
LOOONA_WEBHOOK_URL: the address Looona calls.LOOONA_WEBHOOK_SECRET: the key that signs each call, so your server knows it comes from Looona.LOOONA_WEBHOOK_EVENTS: the events to send, separated by commas. Only these are sent.
Without the address or the secret, nothing is sent and every change goes through.
Before and after
Each change has two events:
BEFORE_…is sent before the change. Looona waits for the answer, 5 seconds at most. A2xxanswer lets the change go through. Anything else refuses it, and the person sees "Webhook validation failed".AFTER_…is sent once the change is made. Looona doesn't wait, and the answer changes nothing.
A BEFORE_ event your server doesn't answer refuses the change: if your server is down, so is that part of Looona. BEFORE_CREATE_REPORT runs for every response. Send only the BEFORE_ events you need.
The events
| Change | Events |
|---|---|
| A response comes in, from a form or the API | BEFORE_CREATE_REPORT, AFTER_CREATE_REPORT |
| A response changes, one or several at once | BEFORE_UPDATE_REPORT, AFTER_UPDATE_REPORT, BEFORE_UPDATE_REPORTS, AFTER_UPDATE_REPORTS |
| A response is deleted | BEFORE_DELETE_REPORT, AFTER_DELETE_REPORT |
| A destination is added, changed or removed | BEFORE_CREATE_REPORTER, AFTER_CREATE_REPORTER, BEFORE_UPDATE_REPORTER, AFTER_UPDATE_REPORTER, BEFORE_DELETE_REPORTER, AFTER_DELETE_REPORTER |
| A member is added, changed or removed | BEFORE_CREATE_USER, AFTER_CREATE_USER, BEFORE_UPDATE_USER, AFTER_UPDATE_USER, BEFORE_DELETE_USER, AFTER_DELETE_USER |
| A password changes | BEFORE_USER_UPDATE_PASSWORD, AFTER_USER_UPDATE_PASSWORD |
| An API key is made, changed or deleted | BEFORE_CREATE_API_KEY, AFTER_CREATE_API_KEY, BEFORE_UPDATE_API_KEY, AFTER_UPDATE_API_KEY, BEFORE_DELETE_API_KEY, AFTER_DELETE_API_KEY |
| A form is made, published or deleted | BEFORE_CREATE_FORM, AFTER_CREATE_FORM, BEFORE_PUBLISH_FORM, AFTER_PUBLISH_FORM, BEFORE_DELETE_FORM, AFTER_DELETE_FORM |
What Looona sends
A POST with a JSON body: the event, and what the change is about.
{
"event": "AFTER_PUBLISH_FORM",
"payload": { "id": "5b0d7c1e-3f4a-4e8b-9a2d-6c1f0e8b7a34", "version": 3 }
}
The payload holds what Looona received for the change: a response's title, answers and who sent it, a form's id, a member's name, email and role. A password is never in it, nor an API key itself: a response sent with a key names the key's ID.
Three headers come with it:
X-Signature: the signature, in hexadecimal.X-Timestamp: when it was sent, in milliseconds.X-Nonce: a value used once.
Check the signature
The signature is an HMAC-SHA256 of the timestamp, a dot, then the body exactly as received, signed with your secret. Check it before trusting a call. For example, in TypeScript on Node.js:
import { createHmac, timingSafeEqual } from "node:crypto"
const isFromLooona = (body: string, headers: Headers, secret: string) => {
const timestamp = headers.get("X-Timestamp") ?? ""
const signature = headers.get("X-Signature") ?? ""
const expected = createHmac("sha256", secret)
.update(`${timestamp}.${body}`)
.digest("hex")
const isRecent = Math.abs(Date.now() - Number(timestamp)) < 5 * 60_000
return isRecent && signature.length === expected.length &&
timingSafeEqual(Buffer.from(signature), Buffer.from(expected))
}
Refuse a call that is too old, or whose X-Nonce you already saw: someone may be sending it again.