Receive webhooks
Connect a destination, verify the signature, retry safely.
Alerts are delivered as signed JSON POST requests to a destination you own. Webhooks are
the only alert channel offered to API integrations; the site also supports chat and email,
but apps use webhooks.
Connect a destination
curl -s -X POST "$API/notifications/destinations" \
-H "X-API-Key: $DEJABARS_KEY" \
-H 'Content-Type: application/json' \
-d '{
"channel": "webhook",
"target": "https://example.com/hooks/dejabars",
"label": "prod"
}'
The response contains the destination id and a secret. The secret is shown once. Store
it in your secret manager; it is what proves a delivery came from us.
The URL must be public https (or http for local testing). Private addresses and
loopback hosts are rejected, so a compromised account cannot use the webhook as a probe
into your network.
Send a test
curl -s -X POST "$API/notifications/destinations/<destination_id>/test" \
-H "X-API-Key: $DEJABARS_KEY"
The test is a real delivery. Check the receiver's log before you create the watch.
The request
Every delivery is a JSON body with these headers:
X-DejaBars-Signature: sha256=<hex>
X-DejaBars-Timestamp: 1763000000
X-DejaBars-Delivery: 8d3f…
X-DejaBars-Event: watch.hit
Content-Type: application/json
{
"event": "watch.hit",
"delivery_id": 3,
"occurred_at": "2026-11-13T19:11:03Z",
"title": "Pattern found · BTCUSDT 1m",
"body": "Verify — 1m dtw alert · dtw · score 0.128 · 2026-11-13 19:00 UTC → 19:04 UTC",
"link": "https://dejabars.com/alerts/9?hit=37696",
"data": {
"watch": { "id": 9, "name": "Verify — 1m dtw alert" },
"hit": {
"symbol": "BTCUSDT",
"timeframe": "1m",
"engine": "dtw",
"score": 0.128,
"direction": "up",
"start_ts": 1794596400,
"end_ts": 1794596640,
"alert_id": 37696
}
},
"notice": "Alert only. This message is not a trading instruction."
}
The payload is deliberately not executable: it has no side, size, price or order type.
Which pattern is this?
Every alert names the watch that produced it: data.watch.id and data.watch.name.
Read the watch to get the pattern itself:
curl -s -H "X-API-Key: $DEJABARS_KEY" "$API/watches/9"
The response contains the exact pattern and xs points, the coins, and the
lanes (timeframe, engines, tolerance, window bounds). That is the answer to "what is
this pattern" — the alert is an observation about those points, not a named shape.
Alerts for one pattern only
A watch is one pattern. Create one watch per pattern, and the alert's data.watch.id
tells you which one fired.
- Every enabled webhook destination on the account receives every watch hit. There is
no per-watch destination binding today.
- If one receiver serves several patterns, filter on
data.watch.id(or
data.watch.name) before acting.
- If you need physically separate endpoints, use separate accounts for the products, or
keep one receiver and route by data.watch.id.
A receiver check:
const PATTERN_ID = 9;
if (payload.event === "watch.hit" && payload.data.watch.id === PATTERN_ID) {
// this is the only pattern this receiver cares about
}
Verify the signature
Recompute the HMAC over ${timestamp}.${rawBody} with your secret and compare it to the
header. Use the raw body text, not a re-serialised object.
import crypto from "node:crypto";
export function verifyDejaBars(rawBody, timestamp, signature, secret) {
const now = Math.floor(Date.now() / 1000);
if (Math.abs(now - Number(timestamp)) > 300) return false; // replay window
const expected =
"sha256=" +
crypto.createHmac("sha256", secret).update(`${timestamp}.${rawBody}`).digest("hex");
return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(signature));
}
The server also sends X-DejaBars-Signature-Window, the number of seconds the timestamp
is valid for. Reject anything outside it.
Retries and failures
- A
2xxresponse acknowledges the delivery. Anything else is a failure. - A failure is retried up to six attempts with backoff. A
429/5xxis retried; a4xx
caused by the payload is not useful to retry, but the attempt is recorded either way.
- Use the delivery id for idempotency. A retry carries the same
delivery_id. - Inspect what happened:
curl -s -H "X-API-Key: $DEJABARS_KEY" "$API/notifications/deliveries?limit=20"
Each row has channel, event_type, state, attempts and last_error.
Pause, re-enable, remove
curl -s -X DELETE -H "X-API-Key: $DEJABARS_KEY" \
"$API/notifications/destinations/<destination_id>"
curl -s -X POST -H "X-API-Key: $DEJABARS_KEY" \
"$API/notifications/destinations/<destination_id>/enable"
Removing a destination stops future deliveries; the delivery log stays for the retention
window.
A receiver checklist
- Verify the signature before parsing the body.
- Reject timestamps outside the window.
- Deduplicate on
delivery_id. - Answer
2xxquickly; do the real work asynchronously. - Never trade automatically from an alert. The payload is an observation, not advice.
Open the interactive reference and run the operation with your key.
