Sari la conținut

Webhooks

Webhooks

Cu ajutorul webhook-urilor primești notificări în timp real atunci când apar evenimente în workspace-ul tău — de exemplu, când un cod QR este scanat.

Creare webhook

Terminal window
POST /v1/webhooks
{
"url": "https://example.com/webhooks/qr3",
"events": ["qr.scanned", "qr.created"],
"secret": "my-secret-key-min-16-chars"
}

Răspuns

{
"id": "wh_abc123",
"url": "https://example.com/webhooks/qr3",
"events": ["qr.scanned", "qr.created"],
"is_active": true,
"secret": "my-secret-key-min-16-chars",
"secret_hint": "my-s…",
"created_at": "2026-03-15T10:00:00.000Z"
}

Tipuri de evenimente

EvenimentDescriere
*Toate evenimentele
qr.createdCod QR creat
qr.updatedCod QR actualizat (URL, status, etichete)
qr.deletedCod QR șters
qr.scannedCod QR scanat
qr.flaggedCod QR marcat ca nesigur
scan.createdEveniment de scanare (alias pentru qr.scanned)
workspace.updatedWorkspace actualizat
webhook.pingPing de test (prin endpoint-ul /ping)

Formatul payload-ului

Toate payload-urile webhook-urilor au acest format:

{
"id": "evt_abc123xyz",
"type": "qr.scanned",
"created": "2026-03-15T10:00:00.000Z",
"data": {
"code_id": "qr_abc123",
"short_code": "r7f3Kx",
"scan_id": "scn_xyz",
"country": "AT",
"device_type": "mobile",
"os": "iOS"
}
}

Verificarea semnăturii

qr3.app semnează fiecare cerere de webhook cu HMAC-SHA256:

X-QR3-Signature: sha256=a1b2c3d4e5f6...

Implementarea verificării

import crypto from "crypto";
function verifySignature(
payload: string,
signature: string,
secret: string
): boolean {
const expected = crypto
.createHmac("sha256", secret)
.update(payload)
.digest("hex");
const received = signature.replace("sha256=", "");
return crypto.timingSafeEqual(
Buffer.from(expected, "hex"),
Buffer.from(received, "hex")
);
}
// In Express:
app.post("/webhooks/qr3", (req, res) => {
const signature = req.headers["x-qr3-signature"] as string;
const valid = verifySignature(
JSON.stringify(req.body),
signature,
process.env.QR3_WEBHOOK_SECRET
);
if (!valid) return res.status(401).json({ error: "Invalid signature" });
const event = req.body;
console.log(event.type, event.data);
res.json({ received: true });
});

Logica de reîncercare

În caz de erori (HTTP >= 300 sau timeout), qr3.app reîncearcă livrarea:

ÎncercareÎntârziere
1Imediat
21 minut
35 minute

După 10 erori consecutive, webhook-ul este dezactivat automat.

Jurnale de livrare

Terminal window
GET /v1/webhooks/:id/deliveries
{
"data": [
{
"id": "whd_abc123",
"event_type": "qr.scanned",
"status": "success",
"status_code": 200,
"response_time_ms": 145,
"attempt": 1,
"created_at": "2026-03-15T10:00:00.000Z"
}
]
}

Ping de test

Testează un webhook imediat:

Terminal window
POST /v1/webhooks/:id/ping

Aceasta trimite un eveniment webhook.ping către URL-ul endpoint-ului tău.