Webhookit
Webhookit
Webhookien avulla vastaanotat reaaliaikaisia ilmoituksia, kun työtilassasi tapahtuu jotain – esimerkiksi kun QR-koodi skannataan.
Luo webhook
POST /v1/webhooks{ "url": "https://example.com/webhooks/qr3", "events": ["qr.scanned", "qr.created"], "secret": "my-secret-key-min-16-chars"}Vastaus
{ "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"}Tapahtumatyypit
| Tapahtuma | Kuvaus |
|---|---|
* | Kaikki tapahtumat |
qr.created | QR-koodi luotu |
qr.updated | QR-koodi päivitetty (URL, tila, tagit) |
qr.deleted | QR-koodi poistettu |
qr.scanned | QR-koodi skannattu |
qr.flagged | QR-koodi merkitty epäturvalliseksi |
scan.created | Skannaustapahtuma (alias tapahtumalle qr.scanned) |
workspace.updated | Työtila päivitetty |
webhook.ping | Testi-ping (kautta /ping-päätepisteen) |
Payload-muoto
Kaikilla webhook-payloadeilla on seuraava muoto:
{ "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" }}Allekirjoituksen varmennus
qr3.app allekirjoittaa jokaisen webhook-pyynnön käyttämällä HMAC-SHA256-menetelmää:
X-QR3-Signature: sha256=a1b2c3d4e5f6...Toteuta varmennus
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 });});import hmacimport hashlib
def verify_signature(payload: str, signature: str, secret: str) -> bool: expected = hmac.new( secret.encode(), payload.encode(), hashlib.sha256 ).hexdigest() received = signature.removeprefix("sha256=") return hmac.compare_digest(expected, received)Uudelleenyrityslogiikka
Virhetilanteissa (HTTP >= 300 tai aikakatkaisu) qr3.app yrittää toimitusta uudelleen:
| Yritys | Viive |
|---|---|
| 1 | Heti |
| 2 | 1 minuutti |
| 3 | 5 minuuttia |
10 peräkkäisen virheen jälkeen webhook poistetaan automaattisesti käytöstä.
Toimituslokit
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" } ]}Testi-ping
Testaa webhookia heti:
POST /v1/webhooks/:id/pingTämä lähettää webhook.ping-tapahtuman päätepisteen URL-osoitteeseen.