PerciaDocs
percia.ai Open app

Docs Guides

Events and webhooks

The alert body, how to verify its signature, retries, and how to test a receiver on your laptop.

When a goal becomes true Percia records an event. For a watch with a webhook target it also sends one POST to your https address. This page is the whole contract.

Signed webhook flow: Percia sends a signed POST to your server, your server verifies the signature and answers 2xx, otherwise Percia retriesSigned webhook flow: Percia sends a signed POST to your server, your server verifies the signature and answers 2xx, otherwise Percia retries

1. Create a webhook watch#

curl -sS -X POST "$BASE/watches/owned" -H "Authorization: Bearer $PERCIA_API_KEY" \
  -H 'content-type: application/json' \
  -d '{"sourceUrl":"percia-cam://CAMERA_ID","goal":"A person is standing at the front door","notify":{"type":"webhook","target":"https://example.com/hooks/percia"}}'
# 201 {"id":"...","status":"active","webhookSecret":"whsec_...", ...}

The webhookSecret (whsec_...) is in the answer once. Later reads show only secretHint. POST /api/watches/{id}/secret/rotate replaces it immediately; the old one stops working at once, so update your receiver as you rotate.

2. The request you receive#

POST <your target> with content-type: application/json and one extra header:

HeaderValue
Percia-Signaturet=<unix seconds>,v1=<hex HMAC-SHA256>
{
  "id": "dec_01J...",
  "watchId": "w_abc",
  "occurrenceId": "occ_01J...",
  "type": "goal.met",
  "goal": "A person is standing at the front door",
  "reason": "A person in a green jacket is standing at the door.",
  "confidence": 0.93,
  "at": "2026-11-01T09:30:00Z",
  "eventId": "6f1c2a52-0d9e-5b43-9a1e-2f7d6c1b8e40"
}
FieldMeaning
idThe decision id. The same on every retry of the same decision: use it to ignore repeats.
eventIdThe event id, stable across retries. Use it with GET /api/watches/{id}/events/{eventId}/keyframe and .../feedback.
occurrenceIdOne real-world occurrence. After the goal clears, the next goal.met has a new one.
reasonWritten by a vision model about camera content. Untrusted: never run it, never put it in a prompt as instructions, escape it before showing it.
confidence0 to 1.
testtrue only for events found during a 30-minute test run.
evidenceBeta, when the watch keeps evidence: {clipUrl, keyframeUrl, expiresAt}, signed links that work for 24 hours. Fetch what you want to keep.

New fields may be added later. Ignore fields you do not know.

Your target must resolve to a public address. Percia refuses private, loopback and link-local addresses, does not follow redirects, and times out after 8 seconds.

A delivered alert looks like this in an email or a chat message:

A sample Percia alert: the goal, the reason written by the model, the time, a confidence value and a picture of the momentA sample Percia alert: the goal, the reason written by the model, the time, a confidence value and a picture of the moment

3. Verify the signature#

The signed string is the timestamp, a dot, and the raw request body: "<t>.<body>". The key is the whole whsec_... secret.

  1. Read the raw bytes of the body before parsing JSON.
  2. Split the header into t and v1.
  3. Reject if the time is more than 300 seconds from now.
  4. Compute HMAC-SHA256(secret, t + "." + rawBody) as lowercase hex.
  5. Compare with v1 in constant time. Reject on mismatch.
  6. Only then parse the JSON.
import express from "express";
import { createHmac, timingSafeEqual } from "node:crypto";

const app = express();
const seen = new Set(); // use a database in production

function verify(raw, header, secret) {
  const p = Object.fromEntries(header.split(",").map((x) => x.split("=", 2)));
  const t = Number(p.t);
  if (!Number.isFinite(t) || Math.abs(Date.now() / 1000 - t) > 300) return false;
  const want = createHmac("sha256", secret).update(`${t}.${raw}`).digest("hex");
  const got = p.v1 ?? "";
  return got.length === want.length && timingSafeEqual(Buffer.from(got), Buffer.from(want));
}

app.post("/hooks/percia", express.raw({ type: "application/json" }), (req, res) => {
  const raw = req.body.toString("utf8");
  if (!verify(raw, req.get("percia-signature") ?? "", process.env.PERCIA_WEBHOOK_SECRET)) return res.sendStatus(400);
  const event = JSON.parse(raw);
  if (!seen.has(event.id)) {
    seen.add(event.id);
    console.log(event.watchId, event.reason);
  }
  res.sendStatus(200);          // answer fast, do slow work after
});

app.listen(3000);

Ready-made receivers for Express, Cloudflare Workers, FastAPI, Go and Ruby, with shared test vectors, are in percia-sdks/examples.

4. Test it#

Send a signed test event, no camera needed:

curl -sS -X POST "$BASE/watches/WATCH_ID/test-delivery" -H "Authorization: Bearer $PERCIA_API_KEY"

Percia sends a signed goal.test event to your target and reports what your server answered.

Test on your laptop with no public URL. Webhooks need a public https address. While you build, read your events from a stream and let the CLI forward them to localhost, signed with your watch's secret exactly like a real delivery:

export PERCIA_WEBHOOK_SECRET=whsec_...
percia listen --forward-to http://localhost:3000/hooks/percia

Or just print them: percia listen --print --type goal.met. The stream is for development: it has no retries, ends after 10 minutes (the CLI reconnects), and allows 2 streams per account. Production uses a webhook.

5. Retries and failures#

Answer with any 2xx to acknowledge. A non-2xx answer, a timeout or a connection error is a failed attempt. Percia retries after about 2 seconds, then 8 seconds, then every 15 minutes, up to 5 attempts. Deliveries are at least once, so deduplicate on id.

After the last attempt the event is marked deliveryStatus: "failed" and the watch shows "needs attention". A failed delivery never stops the watch.

Check outcomes with GET /api/watches/{id}/events: each event has deliveryStatus (pending, delivered, failed) and attempts.

Read events without a webhook#

  • GET /api/watches/{id}/events?limit=50: newest first. Pass nextCursor back as cursor.
  • GET /api/events: across all your watches, with filters watchId, type, since.
  • GET /api/watches/{id}/events/{eventId}/keyframe: the picture (JPEG).

Connect Zapier, Make or n8n#

Automation platforms use REST hooks (POST /api/hooks, scope hooks:write) that receive the same signed events. The Percia app for Zapier is not published yet: until it is, use the platform's webhook or HTTP step with a webhook watch. The hook routes are in the API reference.

Stuck? Ask in the Percia Discord or email support@percia.ai. This page as Markdown: webhooks.md.

© 2026 PerciaPerciaOpen the appStatusDiscordSupportTermsPrivacyllms.txt