Webhooks
Receive CookieBeam events as signed HTTP POST requests on your own endpoints.
Last updated:
Webhooks deliver CookieBeam events to an HTTPS endpoint you control. Webhooks are a plan-gated feature, and endpoint management is currently restricted: endpoints are configured for your team by CookieBeam rather than self-served in the dashboard. Each endpoint subscribes to a set of event types and has a signing secret, which starts with whsec_.
There are no public REST endpoints for webhook management. The webhooks:read and webhooks:write API key scopes exist on keys but currently gate nothing.
Event types
These event types are emitted today:
| Event | When |
|---|---|
consent.given | A visitor made an explicit consent choice in the banner, or a choice was stored with POST /api/v1/consent/log. Machine-written default states do not emit it |
consent.withdrawn | A visitor's explicit banner choice took back a category that their previous explicit choice on the same banner granted. The same choice also emits consent.given |
consent.form_recorded | A given or confirmed form consent proof was stored |
consent.form_withdrawn | A form consent withdrawal was stored |
preferences.updated | A person's marketing preferences changed, through the API, the hosted page or the dashboard |
scan.completed | A cookie scan finished |
scan.new_tracker_detected | A scan added cookies, storage items, scripts or network connections to the banner's inventory that were not in it. One event per scan |
scan.policy_update_needed | A scan found trackers that differ from the published banner version |
dsar.request_submitted | A data subject access request was submitted |
banner.published | A banner configuration was published |
compliance.report_generated | A monthly compliance report was generated |
consent.withdrawn is about banner consent only. A withdrawn form consent proof sends consent.form_withdrawn, and a marketing preference change sends preferences.updated. A visitor's first choice is never a withdrawal, even when it declines categories, and neither is declining after a default state the banner set before the visitor chose (for example the granted default in an opt-out region). Choices stored with POST /api/v1/consent/log do not emit it. When the banner carries a consent ID and the server finds a stored choice by that ID, previousConsentLogId points to it and withdrawnCategories lists the categories that choice granted but the new one does not. When no stored choice is found by consent ID, previousConsentLogId is null and withdrawnCategories comes from the banner script's own report of what the visitor took back, with necessary and any category the new choice still grants removed. In the rare case that the same choice arrives twice, two events can share the same non-null previousConsentLogId; use it to drop the repeat.
scan.new_tracker_detected compares against the inventory as it is when the scan runs. An item still in the inventory does not emit it again, including one marked inactive because a later scan no longer saw it. An item that was removed from the inventory and is found again is reported again: CookieBeam deletes cookies that have been inactive for 30 days, and deleting an item or resetting detection in the dashboard removes it too. Items added by a scan are the only trigger; items added from live-site drift reports or by hand do not emit it. The first scan of a banner reports every item it finds.
Delivery format
Each delivery is an HTTP POST with a JSON envelope:
{
"event": "consent.given",
"data": {
"consentLogId": "9b2f7c14-8b3a-4e21-9d5c-1a2b3c4d5e6f",
"bannerId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"publicBannerId": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
"consentId": "c0nsent-7Hq2Lx9P",
"method": "accept_all",
"consentGiven": { "necessary": true, "analytics": true, "marketing": true },
"country": "DE",
"region": null,
"domain": "example.com",
"timestamp": "2026年08月13日T12:00:00.000Z"
},
"timestamp": "2026年08月13日T12:00:01.000Z",
"deliveryId": "d290f1ee-6c54-4b01-90e6-d701748f0851"
}
Every event shares this envelope; data depends on the event type. See Event payloads.
Request headers:
| Header | Value |
|---|---|
Content-Type | application/json |
User-Agent | CookieBeam-Webhooks/1.0 |
X-CookieBeam-Timestamp | Unix time in seconds when the delivery was signed |
X-CookieBeam-Signature-V1 | One or more v1=<hex> entries, comma-separated: HMAC-SHA256 of timestamp + "." + raw body, keyed with an endpoint secret |
X-CookieBeam-Event | The event type, for example consent.given |
X-CookieBeam-Delivery | The delivery ID, matching deliveryId in the body |
X-CookieBeam-Signature | Legacy, only for endpoints created before timestamped signatures (see below): HMAC-SHA256 hex digest of the raw body |
Event payloads
The fields of data for each event type. IDs are UUIDs and times are ISO 8601 strings unless noted. bannerId is always the banner's internal ID.
| Event | data fields |
|---|---|
consent.given from the banner | consentLogId, bannerId, publicBannerId, consentId, method, consentGiven (the stored choices), country, region, domain, timestamp |
consent.given from POST /api/v1/consent/log | consentLogId, bannerId, consentGiven, pageUrl (always null), timestamp |
consent.withdrawn | consentLogId, previousConsentLogId (the choice that granted what was taken back, or null when no prior choice was found by consent ID), bannerId, publicBannerId, consentId, method, withdrawnCategories (category IDs, sorted; never necessary), consentGiven (the new stored choices), country, region, domain, timestamp |
consent.form_recorded, consent.form_withdrawn | proofId, formId, event (given, confirmed or withdrawn), confirmsId, subjectType, subjectRef, purposes, recordedAt |
preferences.updated | subjectType, subjectRef, source (api, link or dashboard), changes (array of { topicKey, channel, status }), updatedAt |
scan.completed | scanId, bannerId, url, totalCookies, categoryCounts, submittedBy, submittedAt, metadata |
scan.new_tracker_detected | scanId, bannerId, url, newTrackerCount, newTrackers (at most 100 items, each { itemType, id, name, domain, category, vendor }, plus storageType for cookies and requestType for connections), truncated (true when newTrackerCount is over 100), detectedAt |
scan.policy_update_needed | scanId, bannerId, url, publishedVersionId, publishedVersionNumber, newTrackers, removedTrackers, newTrackerCount, removedTrackerCount, checkedAt |
dsar.request_submitted | requestId, bannerId, bannerName, requestType, canonicalRequestType, requesterEmail, requesterName, status, submittedAt, receivedAt, deadlineAt, slaPolicy, deadlineBasis (optional, "statutory" or "target") |
banner.published | bannerId, publicBannerId, versionId, versionNumber, versionName, buildStatus, publishedBy, publishedAt |
compliance.report_generated | period, teamId, reportStatus (always final), reportRunId, idempotencyKey, report (the report object) |
Form consent and preference events never contain the person's e-mail address or phone number, only subjectRef. dsar.request_submitted does contain the requester's e-mail address and name, so treat the receiving endpoint as handling personal data.
In scan.new_tracker_detected, itemType is cookie (cookies, local and session storage, and tracking pixels), script or connection, and name is the cookie or storage key, the script URL (a content fingerprint for inline scripts), or the connection's domain and path pattern.
For dsar.request_submitted, receivedAt is the time the submission was received and starts the deadline clock; submittedAt is the later verification time. requestType keeps the value do_not_sell for any request submitted as do_not_sell from any location, and for sale/sharing opt_out_sale requests from visitors located in California (determined by the visitor's edge geo headers, not the embed's data-cb-region attribute), so existing receivers don't break. canonicalRequestType always carries the canonical value (for example opt_out_sale). Match on canonicalRequestType for new integrations.
A consent.form_recorded delivery:
{
"event": "consent.form_recorded",
"data": {
"proofId": "7b9e2c14-6a3d-4f58-9e01-2c3d4e5f6a7b",
"formId": "newsletter-footer",
"event": "given",
"confirmsId": null,
"subjectType": "email",
"subjectRef": "k1:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
"purposes": ["newsletter"],
"recordedAt": "2026年10月22日T09:15:00.412Z"
},
"timestamp": "2026年10月22日T09:15:01.020Z",
"deliveryId": "0f8e7d6c-5b4a-4392-8170-6f5e4d3c2b1a"
}
Verify the signature
Verify X-CookieBeam-Signature-V1 before you trust a delivery:
- Read
X-CookieBeam-Timestamp. Reject the request if it is missing, not a whole number, or more than 300 seconds away from your clock. This stops a captured request from being replayed later. - Build the signed string: the timestamp, a dot, then the raw request body exactly as received.
- For each secret you accept (normally one; two while you rotate), compute the HMAC-SHA256 hex digest of that string.
- Split
X-CookieBeam-Signature-V1on commas and keep the entries that start withv1=. Accept the request if any entry equals one of your digests, compared in constant time. Otherwise reject it.
Node.js (Express), with the raw body kept for verification:
const crypto = require('node:crypto');
const express = require('express');
const SECRETS = [process.env.COOKIEBEAM_WEBHOOK_SECRET]; // add the old secret while you rotate
const TOLERANCE_SECONDS = 300;
function verifyCookieBeamSignature(rawBody, headers) {
const timestamp = headers['x-cookiebeam-timestamp'];
if (!/^\d+$/.test(timestamp ?? '')) return false;
if (Math.abs(Math.floor(Date.now() / 1000) - Number(timestamp)) > TOLERANCE_SECONDS) return false;
const candidates = (headers['x-cookiebeam-signature-v1'] ?? '')
.split(',')
.map((entry) => entry.trim())
.filter((entry) => entry.startsWith('v1='))
.map((entry) => entry.slice(3));
return SECRETS.some((secret) => {
const expected = crypto
.createHmac('sha256', secret)
.update(`${timestamp}.${rawBody}`)
.digest('hex');
return candidates.some((candidate) =>
candidate.length === expected.length &&
crypto.timingSafeEqual(Buffer.from(candidate), Buffer.from(expected)));
});
}
const app = express();
app.post('/webhooks/cookiebeam', express.raw({ type: 'application/json' }), (req, res) => {
const rawBody = req.body.toString('utf8');
if (!verifyCookieBeamSignature(rawBody, req.headers)) return res.sendStatus(400);
const delivery = JSON.parse(rawBody);
// Ignore deliveries you have already processed: delivery.deliveryId is stable across retries.
console.log(delivery.event, delivery.deliveryId);
res.sendStatus(204);
});
Python (Flask):
import hashlib
import hmac
import os
import time
from flask import Flask, abort, request
SECRETS = [os.environ["COOKIEBEAM_WEBHOOK_SECRET"]] # add the old secret while you rotate
TOLERANCE_SECONDS = 300
app = Flask(__name__)
def verify_cookiebeam_signature(raw_body: bytes, headers) -> bool:
timestamp = headers.get("X-CookieBeam-Timestamp", "")
if not timestamp.isdigit():
return False
if abs(int(time.time()) - int(timestamp)) > TOLERANCE_SECONDS:
return False
candidates = [
entry.strip()[3:]
for entry in headers.get("X-CookieBeam-Signature-V1", "").split(",")
if entry.strip().startswith("v1=")
]
signed = timestamp.encode() + b"." + raw_body
for secret in SECRETS:
expected = hmac.new(secret.encode(), signed, hashlib.sha256).hexdigest()
if any(hmac.compare_digest(expected, candidate) for candidate in candidates):
return True
return False
@app.post("/webhooks/cookiebeam")
def cookiebeam_webhook():
raw_body = request.get_data() # the bytes exactly as received
if not verify_cookiebeam_signature(raw_body, request.headers):
abort(400)
delivery = request.get_json()
# Ignore deliveries you have already processed: delivery["deliveryId"] is stable across retries.
print(delivery["event"], delivery["deliveryId"])
return "", 204
The secret is the whole value you were given, including the whsec_ prefix; use it as the HMAC key as-is.
Use the raw body as received. Parsing and re-serializing the JSON can change the bytes and produce a false mismatch.
The v1= prefix names the signature scheme. A later scheme would be added as another prefix in the same header, so ignore entries you do not recognise rather than failing on them.
The legacy X-CookieBeam-Signature header
Endpoints created before timestamped signatures still receive X-CookieBeam-Signature, unchanged in name and format: the HMAC-SHA256 hex digest of the raw body alone, keyed with the endpoint secret. Receivers that verify it today keep working.
It has no timestamp, so it does not protect against replays. It is sent for each existing endpoint until that endpoint's end date, which is announced by email at least six months ahead, with a reminder one month before. Once your receiver verifies X-CookieBeam-Signature-V1, you can ask CookieBeam to switch it off earlier for that endpoint; switching it off cannot be undone. Endpoints created now receive only the v1 headers.
If your receiver checks both during the move, check them separately. Never accept a request on the legacy digest after the v1 check failed: that would let an old captured request through.
Signing secrets
The signing secret is shown once, when the endpoint is created or the secret is rotated, and is stored encrypted. It cannot be displayed again; if you lose it, ask CookieBeam to rotate it.
Rotating creates a new secret. You can keep the old one signing for up to 72 hours so you can update your receiver without missing events. During that overlap X-CookieBeam-Signature-V1 carries one v1= entry per secret (the new one first), and the legacy header, where it is still sent, stays signed with the old secret until the overlap ends.
Duplicates
A delivery can arrive more than once, for example when your endpoint answered after the 10-second timeout. Use X-CookieBeam-Delivery (or deliveryId in the body) to ignore deliveries you have already processed.
Receiving requirements
Your endpoint must:
- Use HTTPS with a publicly resolvable host. Private, loopback, and reserved IP addresses are rejected when the endpoint is created and again at delivery time.
- Answer directly. Redirects are refused and count as failed deliveries.
- Respond within 10 seconds. The response body is recorded only up to 4,000 characters.
- Return a 2xx status to acknowledge a delivery. Any other outcome follows the retry policy below.
Retries and disabling
Deliveries are queued and sent by a background runner that processes pending deliveries every few minutes. Each delivery is claimed by one run at a time, so overlapping runs do not send it twice.
A failed delivery is tried up to 8 times in total over about 27 hours: immediately, then after 1 minute, 5 minutes, 30 minutes, 2 hours, 5 hours, 10 hours and 10 hours. Each delay includes random variation so that queued deliveries do not all arrive at once when your endpoint recovers.
Network errors, timeouts, HTTP 5xx, 408, and 429 responses are retried. Other 4xx responses are treated as permanent rejections and are not retried, because the endpoint rejected the request itself.
An endpoint that accumulates 10 consecutive delivery failures is disabled automatically, and the team owner is notified by email. Ask CookieBeam to re-enable the endpoint once it is healthy again.