Signed webhooks for run results
A webhook sends a `run.finished` JSON message to your own HTTPS endpoint each time a run in your workspace finishes.
A webhook sends a run.finished JSON message to your own HTTPS endpoint each time a run in your workspace finishes. Use it to post results into your own tools or to start your own follow-up steps. Every message is signed, so your endpoint can check that it came from HeyBug and was not changed on the way.
What HeyBug sends
Each finished run sends one delivery to every webhook that covers its project. A run finishes as passed, failed, error or canceled, and a webhook gets all four.
Headers on every delivery:
| Header | Value |
|---|---|
Content-Type | application/json |
User-Agent | HeyBug-Webhooks/1 |
HeyBug-Event | run.finished |
HeyBug-Delivery | A delivery id. Retries send the same id. |
HeyBug-Signature | t=<unix seconds>,v1=<hex HMAC-SHA256> |
Example body for a run that has one failing case:
{
"failures": [
{
"caseKey": "TC-4",
"cause": "",
"error": "Expected \"Welcome back\" but found \"Sign in\"",
"status": "failed",
"step": "Submit the sign-in form",
"title": "Signing in shows the dashboard"
}
],
"project": { "id": "prj_8f2c1a", "name": "Storefront" },
"run": {
"counts": { "errored": 0, "failed": 1, "passed": 41, "total": 42 },
"id": "run_3b9d0e",
"number": 128,
"status": "failed",
"url": "https://opentest.nagara.cloud/p/prj_8f2c1a/runs/run_3b9d0e"
},
"type": "run.finished"
}failures lists up to 50 failing or errored cases and is an empty list for a passing run. cause is the likely cause from triage, and it is an empty string when triage has not run for that case.
Set up a webhook
- Open Integrations (
/settings/integrations). Only owners and admins can add or change webhooks. - Select Add webhook.
- Enter an
httpsendpoint URL that HeyBug can reach, and choose one project or every project. - Select Save. The signing secret (it starts with
whsec_) appears once. Copy it now and store it where your endpoint can read it. - Select Test on the webhook. HeyBug sends a sample message with run id
run_testand project idprj_test, so your endpoint can tell test messages from real ones.
The same steps through the API, with a key from Connect an agent:
curl -sS https://opentest.nagara.cloud/api/notification-channels \
-H "Authorization: Bearer <key>" -H "Content-Type: application/json" \
-d '{"kind":"webhook","projectId":"","url":"https://hooks.example.com/heybug"}'An empty projectId covers every project. The response has "secret":{"set":true,"value":"whsec_..."}. Later reads show only "set": true. To send a test message, call POST /api/notification-channels/<id>/test.
Check the signature
The signed text is the timestamp from t, a dot, then the raw body bytes. The signature is the hex HMAC-SHA256 of that text, keyed with the secret. Hash the body exactly as it arrived, not a re-encoded copy. Also reject a timestamp that is too far from your clock, to stop replays. You choose the window.
Node (18 or later):
import { createHmac, timingSafeEqual } from 'node:crypto';
// rawBody is the request body as a string, before JSON.parse.
export function verifyHeyBugSignature(secret, header, rawBody) {
const parts = Object.fromEntries(header.split(',').map((p) => p.split('=')));
if (!parts.t || !parts.v1) return false;
const want = createHmac('sha256', secret).update(`${parts.t}.${rawBody}`).digest('hex');
const a = Buffer.from(want);
const b = Buffer.from(parts.v1);
return a.length === b.length && timingSafeEqual(a, b);
}Go:
package webhook
import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"fmt"
"strings"
)
// Verify checks an HeyBug-Signature header against the raw request body.
func Verify(secret, header string, body []byte) bool {
var t, v1 string
for _, part := range strings.Split(header, ",") {
k, v, _ := strings.Cut(part, "=")
switch k {
case "t":
t = v
case "v1":
v1 = v
}
}
if t == "" || v1 == "" {
return false
}
m := hmac.New(sha256.New, []byte(secret))
fmt.Fprintf(m, "%s.", t)
m.Write(body)
return hmac.Equal([]byte(hex.EncodeToString(m.Sum(nil))), []byte(v1))
}In a handler, read the body with io.ReadAll(r.Body) before any JSON decoding, then pass r.Header.Get("HeyBug-Signature") and the bytes to Verify.
When a delivery fails
A delivery fails when your endpoint does not answer within 10 seconds, answers with a status outside 2xx, or when the address is private. HeyBug checks every redirect the same way, so a redirect to a private address is refused too.
After a failure HeyBug tries again after 1 minute, 5 minutes, 30 minutes, 2 hours and 6 hours. That is six attempts in total. When the last one fails, the delivery stops with the status failed.
- Answer quickly. Return a 2xx status first, then do slow work in a queue. The response body is not read.
- Skip repeats. A retry has the same
HeyBug-Deliveryid but a new signature, so store the ids you have handled and skip any you see again. - Fix the signature check. Use the raw body and the secret from when the webhook was added. If you lost the secret, there is no way to show it again: delete the webhook and add it again, which gives it a new secret.
- Use a public address. Private and local addresses are refused, so a test endpoint on your laptop needs a public tunnel.
- Turn off a webhook. Switching a webhook off stops new deliveries. Deliveries already queued are still sent.
- Test again. Select Test after each change. A failed test shows the reason under the webhook, such as the HTTP status your endpoint returned.