{"schemaVersion":1,"title":"Receive webhooks","url":"https://appgram.dev/docs/guides/webhooks","markdownUrl":"https://appgram.dev/docs/format-md/guides/webhooks.md","jsonUrl":"https://appgram.dev/docs/agent/pages/guides/webhooks.json","version":"current","locale":"en","markdown":"# Receive webhooks\n\nVerify HMAC signatures, deduplicate events, and handle delivery retries.\n\nReceive AppGram events on your server when feedback, support, or other subscribed activity changes. Configure endpoints and event subscriptions in the dashboard's [Developer tools → Webhooks](https://app.appgram.dev/developer/webhooks) area.\n\n## Configure an endpoint\n\n1. Select your project or organization in the [dashboard](https://app.appgram.dev).\n2. Open Webhooks and add the endpoint at the appropriate project or organization scope.\n3. Enter a reachable HTTPS receiver URL and select the event types you need.\n4. Save the signing secret securely when it is shown. Keep it on the receiving server.\n5. Use the endpoint's delivery history or **Developer tools → Logs → Webhook deliveries** to inspect success and failure responses.\n\nThe published REST contract currently exposes a sample-payload operation. Endpoint registration and subscription management are dashboard workflows; they are not additional public API operations implied by that sample endpoint.\n\n## Inspect a sample payload\n\nCopy an exact event type from the dashboard's event catalog:\n\n```bash\ncurl --request GET \\\n  --url 'https://api.appgram.dev/api/v1/webhooks/events/YOUR_EVENT_TYPE/sample' \\\n  --header 'x-api-key: YOUR_API_KEY'\n```\n\nThe sample is synthetic and does not deliver a webhook. The [sample-payload reference](/api/webhooks) describes its response.\n\n## Verify delivery signatures\n\nAppGram posts JSON with these headers:\n\n| Header | Meaning |\n| --- | --- |\n| `X-Webhook-ID` | Identifier for this delivery attempt |\n| `X-Webhook-Timestamp` | Attempt time as Unix seconds |\n| `X-Webhook-Signature` | `t=<unix-seconds>,v1=<hex-signature>` |\n\nThe signature is the lowercase hexadecimal HMAC-SHA256 of **`timestamp + \".\" + raw HTTP body`**, using your endpoint's signing secret. Verify the original request bytes before parsing JSON. Re-serializing JSON changes the bytes and can invalidate a legitimate signature.\n\nThis Node.js verifier rejects malformed signatures and uses a five-minute clock tolerance:\n\n```javascript\nimport { createHmac, timingSafeEqual } from 'node:crypto';\n\nexport function verifyAppGramWebhook(rawBody, signatureHeader, secret, now = Date.now()) {\n  if (!Buffer.isBuffer(rawBody) || typeof signatureHeader !== 'string' || !secret) return false;\n  const match = /^t=(\\d+),v1=([a-f0-9]{64})$/i.exec(signatureHeader);\n  if (!match) return false;\n\n  const timestamp = Number(match[1]);\n  if (!Number.isSafeInteger(timestamp) || Math.abs(now - timestamp * 1000) > 300_000) return false;\n\n  const expected = createHmac('sha256', secret)\n    .update(`${match[1]}.`)\n    .update(rawBody)\n    .digest();\n  return timingSafeEqual(expected, Buffer.from(match[2], 'hex'));\n}\n```\n\nPass the raw request buffer, the `X-Webhook-Signature` value, and your endpoint secret. Reject the request if verification fails. Configure a request-body size limit in your HTTP server. Keep its clock synchronized and choose a tolerance appropriate to your deployment.\n\nOnly parse the JSON after verification succeeds. In frameworks with JSON middleware, preserve the raw body for this route rather than signing `JSON.stringify(parsedBody)`.\n\n## Process once and acknowledge promptly\n\nThe payload includes `id`, `event`, `timestamp`, and event-specific `data`; it can also contain metadata. Use the signed payload's **`id`** for durable deduplication. `X-Webhook-ID` identifies an attempt and changes between retries.\n\nStore accepted events or enqueue them durably, then return a **2xx** response promptly. Return a success response for an already processed event without repeating its side effects. Do not assume delivery order.\n\n## Retries and failures\n\nFailed deliveries can be attempted up to eight times in total. Retry delays increase approximately through 30 seconds, 2 minutes, 10 minutes, 30 minutes, 2 hours, 6 hours, and 24 hours; scheduling and endpoint state affect actual timing. Retries use a fresh attempt timestamp and signature while retaining the event ID.\n\nInspect delivery history when your receiver is unreachable or returns a non-2xx status. Changing a signing secret requires updating the receiving server too. The local signature example does not test your deployed endpoint; verify one actual delivery with your own configured endpoint before relying on the integration.\n\n","contentLocale":"en","isFallback":false,"authorship":{"authors":[],"contributors":[],"reviewedBy":[]}}