Webhooks

Receive your organization's sales in your system, verify the signature and process each event once.

With a webhook, Trama tells your system (an ERP, a back office) when something happens in your organization: it sends a signed POST to an https:// URL of yours. There are two events today, both about sales:

EventWhen it is sent
sale.wonAn opportunity is won and its sale is created
sale.updatedA sale changes. Every change raises its version

A sale recorded with a past close date does not send sale.won, because it is not a sale from today. Its later changes do send sale.updated.

Create an endpoint

With the organization's API key (Authentication), register the URL and the events you want to receive:

curl https://api.trama.so/v1/webhooks \
  -H "Authorization: Bearer $TRAMA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://erp.example.com/trama/webhooks", "eventTypes": ["sale.won", "sale.updated"] }'

The response carries the secret (whsec_…) that signs every delivery. It is shown only once: store it on your server, in an environment variable or in a secrets manager.

  • The URL must be https://, on a public host, with no username or password in it. Otherwise you get a 400 WEBHOOK_ENDPOINT_URL_INVALID.
  • An organization has at most 20 endpoints, disabled ones included. One more returns 409 WEBHOOK_ENDPOINT_LIMIT_REACHED.
  • With status: "disabled" (updateWebhookEndpoint) the endpoint stops receiving: no new events are queued for it, and the deliveries it already had pending wait, without using attempts, until you enable it again.

What arrives

A POST with Content-Type: application/json, User-Agent: Trama-Webhooks/1 and these headers:

HeaderValue
Trama-SignatureThe signature, see below
Trama-Event-IdThe event's id, the same as in the body
Trama-Event-Typesale.won or sale.updated

Both events use the same envelope. A sale.won:

{
  "id": "evt_5d0c8e2b41f7a9c3e6b1d4f08a2c7e95",
  "type": "sale.won",
  "created_at": "2026-11-25T18:04:12.381Z",
  "subject": { "type": "sale", "id": "7b3e9f1a-2c4d-4e8b-9a6f-1d2c3b4a5e6f" },
  "data": {
    "sale": {
      "id": "7b3e9f1a-2c4d-4e8b-9a6f-1d2c3b4a5e6f",
      "number": 87,
      "version": 1,
      "won_at": "2026-11-25T18:04:11.902Z",
      "seller": { "name": "Lucía Fernández", "email": "lucia@agencia.example.com" },
      "holder": {
        "first_name": "Martín",
        "last_name": "Gómez",
        "email": "martin.gomez@example.com",
        "phone": "+5491155550123",
        "document": "30123456"
      },
      "passengers": {
        "adults": 2,
        "children": 0,
        "infants": 0,
        "total": 2,
        "travelers": [
          {
            "first_name": "Martín",
            "last_name": "Gómez",
            "document_type": "DNI",
            "document_number": "30123456",
            "birth_date": "1985-03-14",
            "nationality": "AR",
            "email": "martin.gomez@example.com",
            "phone": "+5491155550123",
            "is_holder": true
          }
        ]
      },
      "destination": "Bariloche",
      "check_in": "2027-01-10",
      "check_out": "2027-01-17",
      "total": { "amount": "3200.50", "currency": "USD" },
      "notes": null,
      "items": [
        {
          "id": "c1a2b3d4-5e6f-4a7b-8c9d-0e1f2a3b4c5d",
          "kind": "lodging",
          "name": "Hotel 7 noches, habitación doble",
          "provider": "Hotel Lago Azul",
          "booking_code": "LA-48213",
          "service_dates": "10/01 al 17/01",
          "flight_number": null,
          "airline": null,
          "departure_at": null,
          "sale": { "amount": "3200.50", "currency": "USD" }
        }
      ]
    }
  }
}
  • subject.id and data.sale.id are the sale's id.
  • Amounts are decimal strings ("3200.50"), so cents are never rounded.
  • created_at is when the event was recorded. The body carries the whole sale with its version, which can be newer than the change that triggered the event.
  • The body holds personal data of the holder and the travelers. Handle it accordingly.

Verify the signature

Trama-Signature: t=1764093852,v1=5f2b…

v1 is a hex HMAC-SHA256 of <t>.<raw body>, keyed with the whole endpoint secret (whsec_… included). t is the Unix second the attempt was sent. While you rotate the secret, two v1 arrive, one per active secret: one match is enough.

Verify before parsing the JSON, on the raw body exactly as it arrived: a re-serialized body does not give the same signature. Also reject a t more than 5 minutes away from your clock, so a captured delivery cannot be replayed.

import { createHmac, timingSafeEqual } from "node:crypto";

const TOLERANCE_SECONDS = 300;

export function verifyTramaSignature(
  rawBody: string,
  header: string,
  secrets: string[] // the current secret and, while rotating, the previous one
): boolean {
  const parts = header.split(",").map((part) => part.trim().split("="));
  const t = parts.find(([name]) => name === "t")?.[1];
  const signatures = parts
    .filter(([name]) => name === "v1")
    .map(([, value]) => Buffer.from(value ?? "", "hex"));
  if (!t || signatures.length === 0) return false;
  if (Math.abs(Date.now() / 1000 - Number(t)) > TOLERANCE_SECONDS) return false;

  return secrets.some((secret) => {
    const expected = createHmac("sha256", secret).update(`${t}.${rawBody}`).digest();
    return signatures.some(
      (given) => given.length === expected.length && timingSafeEqual(given, expected)
    );
  });
}

timingSafeEqual compares in constant time, so the comparison does not let anyone guess the signature byte by byte.

Header names may reach you in lowercase. HTTP header names are case-insensitive, and in Node req.headers holds them in lowercase: read req.headers["trama-signature"], not req.headers["Trama-Signature"]. Headers.get("Trama-Signature") works either way, because it ignores case.

Process each event once

Delivery is at least once: the same event can arrive more than once, and events can arrive out of order.

  • Deduplicate by id. The same event always carries the same id (also in Trama-Event-Id). If you already processed it, answer 2xx and do nothing.
  • Discard stale events by version. Keep the highest version you have seen for each sale and discard an event that carries an equal or lower one.

Answer 2xx quickly and process afterwards: an attempt times out after 8 seconds.

Retries

Only a 2xx counts as delivered. Any other status, a redirect (redirects are not followed), an 8-second timeout or a connection error is a failed attempt, and it is retried:

Failed attemptNext attempt
11 minute later
25 minutes
330 minutes
42 hours
56 hours
612 hours
724 hours
8None: the delivery stays failed

That is 8 attempts over about 45 hours. Every attempt carries a new t and its own signature.

The delivery log. listWebhookDeliveries lists an endpoint's deliveries, newest first, with their status, the attempts, the last HTTP status you answered and when the next attempt is due. It does not include the body.

Retry by hand. retryWebhookDelivery queues a delivered or failed delivery again, due now and with 8 new attempts. A delivery still pending returns 409 WEBHOOK_DELIVERY_ALREADY_PENDING.

Rotate the secret

rotateWebhookEndpointSecret generates a new secret and returns it once. The previous one stays valid for 24 hours (previousSecretExpiresAt): during that time every delivery carries one v1 per secret, so your verifier accepts both while you change your configuration. After 24 hours, only the new one signs.

Rotating again within those 24 hours drops the secret in grace. So that a timeout does not leave you without a valid secret, send an Idempotency-Key unique to each rotation (a UUID works):

  • A retry with the same key within 10 minutes returns the same secret, without rotating again.
  • After those 10 minutes, the same key returns 409 WEBHOOK_SECRET_REPLAY_EXPIRED and rotates nothing. For another rotation, use a new key.
  • If another rotation already replaced that secret, it returns 409 WEBHOOK_SECRET_ROTATION_SUPERSEDED: rotate with a new key.

On this page