Zum Inhalt
SERVOTINGDocs

Für Entwickler

Webhooks

Statt die API abzufragen, kann SERVOTING jeden Vote sofort an deine URL schicken. Webhook-URL und Secret hinterlegst du im Dashboard unter Belohnungen & API.

Anfrage

Hinterlegst du im Dashboard eine Webhook-URL, schickt SERVOTING jeden Vote sofort als POST-Anfrage:

POST /dein-endpunkt
Content-Type: application/json
X-Servoting-Event: vote.created
X-Servoting-Event-Id: evt_3f9c…
X-Servoting-Signature: t=1793888000,v1=<hex hmac-sha256>

{"type":"vote.created","event_id":"evt_3f9c…","player":"Kritz","test":false,"created_at":"2026-11-05T14:12:03+00:00"}

Signatur prüfen

Prüfe die Signatur: HMAC-SHA256 von <t>.<roher Body> mit deinem Webhook-Secret, und lehne Zeitstempel älter als 5 Minuten ab.

// PHP
$body = file_get_contents('php://input');
preg_match('/^t=(\d+),v1=([a-f0-9]{64})$/', $_SERVER['HTTP_X_SERVOTING_SIGNATURE'] ?? '', $m);
$valid = $m && abs(time() - (int) $m[1]) < 300
&& hash_equals(hash_hmac('sha256', $m[1] . '.' . $body, $secret), $m[2]);

// Node.js (rawBody = unveränderter Request-Body als String/Buffer)
const m = /^t=(\d+),v1=([a-f0-9]{64})$/.exec(req.headers['x-servoting-signature'] || '');
let valid = false;
if (m) {
  const expected = crypto.createHmac('sha256', secret).update(`${m[1]}.${rawBody}`).digest();
  valid = Math.abs(Date.now() / 1000 - Number(m[1])) < 300
&& crypto.timingSafeEqual(expected, Buffer.from(m[2], 'hex'));
}
if (!valid) return res.status(401).end();

Antworten und Wiederholungen

Antworte mit einem 2xx-Status. Sonst wiederholt SERVOTING nach 1, 5, 30, 120, 360 und 720 Minuten. Speichere die event_id jedes belohnten Votes und belohne dasselbe Ereignis nie zweimal.