# Recibe eventos por webhook

Suscríbete a eventos del catálogo, mira sus payloads, verifica la firma y responde a tiempo.

Guía Con aprobación Clave secreta

**Antes de empezar.** Crear webhooks pide una clave secreta con el permiso webhooks:write, que se aprueba en soporte: pídelo desde Configuración › API Keys.

## Elige los eventos

`GET /events` devuelve el catálogo de eventos. Te puedes suscribir a un tipo exacto (`deal.won`), a un objeto entero (`deal.*`) o a todos (`*`).

## Crea la suscripción

La respuesta trae el secret con el que se firman las entregas. Se muestra una sola vez: guárdalo.

```bash
curl -X POST https://api.bydomu.com/v1/webhooks \
  -H "X-API-Key: $BYDOMU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://tu-servidor.com/webhooks/bydomu",
    "eventTypes": ["deal.won", "contact.*"],
    "description": "Negocios ganados y contactos"
  }'
```

**Respuesta · 201 · ejemplo**

```json
{
  "data": { "id": "clx1whk001", "secret": "whsec_…" }
}
```

## Verifica la firma

Cada entrega lleva `X-Domu-Signature: t=…,v1=…`: el HMAC-SHA256 de «timestamp.cuerpo» con tu secret. Usa el cuerpo crudo, compara en tiempo constante y rechaza marcas de tiempo viejas.

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

// header = X-Domu-Signature: t=<timestamp>,v1=<hmac>
function verifyWebhook(rawBody, header, secret, toleranceSec = 300) {
  const parts = Object.fromEntries(header.split(",").map((p) => p.split("=")));
  const timestamp = Number(parts.t);
  if (!timestamp || !parts.v1) return false;
  if (Math.abs(Date.now() / 1000 - timestamp) > toleranceSec) return false;
  const expected = createHmac("sha256", secret)
    .update(`${timestamp}.${rawBody}`)
    .digest("hex");
  const a = Buffer.from(expected);
  const b = Buffer.from(parts.v1);
  return a.length === b.length && timingSafeEqual(a, b);
}
```

[En Python, PHP y Go, con un vector de prueba](https://developers.bydomu.com/guias/firma-webhooks)

## Responde a tiempo

Hasta 5 intentos (0 s, 5 s, 30 s, 2 min y 10 min) ante error de red, 429 o 5xx. Responde 2xx en menos de 10 s.

El id de cada entrega es estable: úsalo para descartar las repetidas.

## Mira los payloads

Cada entrega trae el sobre (event, id, type, timestamp, organizationId, actor) y en data las fichas del evento. `event` repite el tipo, salvo en los cuatro eventos de antes, donde trae el nombre legado (todo appointment.created llega con VISIT_SCHEDULED). `GET /events` devuelve un ejemplo y una descripción para cada uno de los 79 eventos del catálogo.

**Entrega · ejemplo**

contact.created:

```
{
  "event": "contact.created",
  "id": "5f3a0c1e-7d2b-4f7e-9a51-0b6c1d2e3f40",
  "type": "contact.created",
  "timestamp": "2026-09-22T14:30:00.000Z",
  "organizationId": "clx1org001",
  "actor": {
    "kind": "SYSTEM",
    "userId": null
  },
  "data": {
    "contact": {
      "id": "clx1con001",
      "code": "C-0042",
      "firstName": "Laura",
      "lastName": "Restrepo",
      "fullName": "Laura Restrepo",
      "email": "laura.restrepo@example.com",
      "phone": "+573000000001",
      "source": "WEBSITE",
      "status": "NEW",
      "type": "CLIENT",
      "score": 0,
      "ownerId": "clx1usr001",
      "preferredCity": null,
      "preferredType": null,
      "budget": null,
      "currency": null,
      "tags": [],
      "createdAt": "2026-09-22T14:30:00.000Z"
    }
  }
}
```

deal.stage_changed:

```
{
  "event": "deal.stage_changed",
  "id": "5f3a0c1e-7d2b-4f7e-9a51-0b6c1d2e3f40",
  "type": "deal.stage_changed",
  "timestamp": "2026-09-22T14:30:00.000Z",
  "organizationId": "clx1org001",
  "actor": {
    "kind": "USER",
    "userId": "clx1usr001"
  },
  "data": {
    "deal": {
      "id": "clx1deal001",
      "code": "N-0042",
      "title": "Compra apartamento Chapinero · Laura Restrepo",
      "value": 450000000,
      "currency": "COP",
      "probability": 60,
      "status": "OPEN",
      "intent": "PURCHASE",
      "leadSource": "PORTAL",
      "lostReason": null,
      "aiCreated": false,
      "agentId": "clx1usr001",
      "contactId": "clx1con001",
      "pipelineId": "clx1pip001",
      "stageId": "clx1stg003",
      "stageName": "Negociación",
      "stageEnteredAt": "2026-09-22T14:30:00.000Z",
      "expectedCloseDate": "2026-10-31T00:00:00.000Z",
      "closedAt": null,
      "createdAt": "2026-09-20T15:05:00.000Z",
      "saasPlanId": null,
      "saasPlanName": null,
      "saasBillingPeriod": null,
      "saasMrrAmount": null,
      "trialStartedAt": null,
      "trialEndsAt": null
    },
    "contact": {
      "id": "clx1con001",
      "code": "C-0042",
      "firstName": "Laura",
      "lastName": "Restrepo",
      "fullName": "Laura Restrepo",
      "email": "laura.restrepo@example.com",
      "phone": "+573000000001",
      "source": "WEBSITE",
      "status": "QUALIFIED",
      "type": "CLIENT",
      "score": 72,
      "ownerId": "clx1usr001",
      "preferredCity": "Bogotá",
      "preferredType": "APARTMENT",
      "budget": 450000000,
      "currency": "COP",
      "tags": [
        "Compra",
        "Chapinero"
      ],
      "createdAt": "2026-09-20T15:04:00.000Z"
    },
    "transition": {
      "fromStageId": "clx1stg002",
      "fromStageName": "Visita agendada",
      "toStageId": "clx1stg003",
      "toStageName": "Negociación",
      "pipelineId": "clx1pip001",
      "lostReason": null,
      "automated": false
    }
  }
}
```

deal.won:

```
{
  "event": "deal.won",
  "id": "5f3a0c1e-7d2b-4f7e-9a51-0b6c1d2e3f40",
  "type": "deal.won",
  "timestamp": "2026-09-22T14:30:00.000Z",
  "organizationId": "clx1org001",
  "actor": {
    "kind": "USER",
    "userId": "clx1usr001"
  },
  "data": {
    "deal": {
      "id": "clx1deal001",
      "code": "N-0042",
      "title": "Compra apartamento Chapinero · Laura Restrepo",
      "value": 450000000,
      "currency": "COP",
      "probability": 100,
      "status": "WON",
      "intent": "PURCHASE",
      "leadSource": "PORTAL",
      "lostReason": null,
      "aiCreated": false,
      "agentId": "clx1usr001",
      "contactId": "clx1con001",
      "pipelineId": "clx1pip001",
      "stageId": "clx1stg005",
      "stageName": "Ganado",
      "stageEnteredAt": "2026-09-22T14:30:00.000Z",
      "expectedCloseDate": "2026-10-31T00:00:00.000Z",
      "closedAt": "2026-09-22T14:30:00.000Z",
      "createdAt": "2026-09-20T15:05:00.000Z",
      "saasPlanId": null,
      "saasPlanName": null,
      "saasBillingPeriod": null,
      "saasMrrAmount": null,
      "trialStartedAt": null,
      "trialEndsAt": null
    },
    "contact": {
      "id": "clx1con001",
      "code": "C-0042",
      "firstName": "Laura",
      "lastName": "Restrepo",
      "fullName": "Laura Restrepo",
      "email": "laura.restrepo@example.com",
      "phone": "+573000000001",
      "source": "WEBSITE",
      "status": "QUALIFIED",
      "type": "CLIENT",
      "score": 72,
      "ownerId": "clx1usr001",
      "preferredCity": "Bogotá",
      "preferredType": "APARTMENT",
      "budget": 450000000,
      "currency": "COP",
      "tags": [
        "Compra",
        "Chapinero"
      ],
      "createdAt": "2026-09-20T15:04:00.000Z"
    },
    "transition": {
      "fromStageId": "clx1stg003",
      "fromStageName": "Negociación",
      "toStageId": "clx1stg005",
      "toStageName": "Ganado",
      "pipelineId": "clx1pip001",
      "lostReason": null,
      "automated": false
    }
  }
}
```

appointment.confirmed:

```
{
  "event": "appointment.confirmed",
  "id": "5f3a0c1e-7d2b-4f7e-9a51-0b6c1d2e3f40",
  "type": "appointment.confirmed",
  "timestamp": "2026-09-22T14:30:00.000Z",
  "organizationId": "clx1org001",
  "actor": {
    "kind": "USER",
    "userId": "clx1usr001"
  },
  "data": {
    "appointment": {
      "id": "clx1apt001",
      "title": "Visita · Apartamento en Chapinero Alto",
      "type": "SHOWING",
      "status": "CONFIRMED",
      "startTime": "2026-09-26T15:00:00.000Z",
      "endTime": "2026-09-26T16:00:00.000Z",
      "location": "Cra 7 #45-12, Bogotá",
      "source": "MANUAL",
      "contactId": "clx1con001",
      "dealId": "clx1deal001",
      "propertyId": "clx1prop001",
      "assigneeId": "clx1usr001",
      "attended": null,
      "cancelReason": null,
      "createdAt": "2026-09-22T14:30:00.000Z"
    },
    "contact": {
      "id": "clx1con001",
      "code": "C-0042",
      "firstName": "Laura",
      "lastName": "Restrepo",
      "fullName": "Laura Restrepo",
      "email": "laura.restrepo@example.com",
      "phone": "+573000000001",
      "source": "WEBSITE",
      "status": "QUALIFIED",
      "type": "CLIENT",
      "score": 72,
      "ownerId": "clx1usr001",
      "preferredCity": "Bogotá",
      "preferredType": "APARTMENT",
      "budget": 450000000,
      "currency": "COP",
      "tags": [
        "Compra",
        "Chapinero"
      ],
      "createdAt": "2026-09-20T15:04:00.000Z"
    },
    "property": {
      "id": "clx1prop001",
      "code": "P-0042",
      "title": "Apartamento en Chapinero Alto con balcón",
      "type": "APARTMENT",
      "transactionType": "SALE",
      "status": "ACTIVE",
      "price": 450000000,
      "rentPrice": null,
      "currency": "COP",
      "city": "Bogotá",
      "neighborhood": "Chapinero Alto",
      "address": "Cra 7 #45-12",
      "bedrooms": 3,
      "bathrooms": 2,
      "area": 85,
      "agentId": "clx1usr001",
      "createdAt": "2026-08-14T16:20:00.000Z"
    }
  }
}
```

message.received:

```
{
  "event": "message.received",
  "id": "5f3a0c1e-7d2b-4f7e-9a51-0b6c1d2e3f40",
  "type": "message.received",
  "timestamp": "2026-09-22T14:30:00.000Z",
  "organizationId": "clx1org001",
  "actor": {
    "kind": "SYSTEM",
    "userId": null
  },
  "data": {
    "message": {
      "id": "clx1msg001",
      "direction": "INBOUND",
      "channel": "WHATSAPP",
      "type": "TEXT",
      "text": "Hola, ¿el apartamento de Chapinero sigue disponible?",
      "mediaUrl": null,
      "conversationId": "clx1cnv001",
      "contactId": "clx1con001",
      "agentId": null,
      "sentByNoa": false,
      "timestamp": "2026-09-22T14:30:00.000Z"
    },
    "conversation": {
      "id": "clx1cnv001",
      "channel": "WHATSAPP",
      "status": "OPEN",
      "priority": "NORMAL",
      "mode": "AI",
      "contactId": "clx1con001",
      "assignedToId": "clx1usr001",
      "intent": "QUIERE_VISITA",
      "lastMessageAt": "2026-09-22T14:30:00.000Z",
      "createdAt": "2026-09-20T15:04:00.000Z"
    },
    "contact": {
      "id": "clx1con001",
      "code": "C-0042",
      "firstName": "Laura",
      "lastName": "Restrepo",
      "fullName": "Laura Restrepo",
      "email": "laura.restrepo@example.com",
      "phone": "+573000000001",
      "source": "WEBSITE",
      "status": "QUALIFIED",
      "type": "CLIENT",
      "score": 72,
      "ownerId": "clx1usr001",
      "preferredCity": "Bogotá",
      "preferredType": "APARTMENT",
      "budget": 450000000,
      "currency": "COP",
      "tags": [
        "Compra",
        "Chapinero"
      ],
      "createdAt": "2026-09-20T15:04:00.000Z"
    }
  }
}
```

property.price_changed:

```
{
  "event": "property.price_changed",
  "id": "5f3a0c1e-7d2b-4f7e-9a51-0b6c1d2e3f40",
  "type": "property.price_changed",
  "timestamp": "2026-09-22T14:30:00.000Z",
  "organizationId": "clx1org001",
  "actor": {
    "kind": "USER",
    "userId": "clx1usr001"
  },
  "data": {
    "property": {
      "id": "clx1prop001",
      "code": "P-0042",
      "title": "Apartamento en Chapinero Alto con balcón",
      "type": "APARTMENT",
      "transactionType": "SALE",
      "status": "ACTIVE",
      "price": 430000000,
      "rentPrice": null,
      "currency": "COP",
      "city": "Bogotá",
      "neighborhood": "Chapinero Alto",
      "address": "Cra 7 #45-12",
      "bedrooms": 3,
      "bathrooms": 2,
      "area": 85,
      "agentId": "clx1usr001",
      "createdAt": "2026-08-14T16:20:00.000Z"
    },
    "priceChange": {
      "previousPrice": 450000000,
      "newPrice": 430000000,
      "currency": "COP"
    }
  }
}
```

lease.expiring:

```
{
  "event": "lease.expiring",
  "id": "5f3a0c1e-7d2b-4f7e-9a51-0b6c1d2e3f40",
  "type": "lease.expiring",
  "timestamp": "2026-09-22T14:30:00.000Z",
  "organizationId": "clx1org001",
  "actor": {
    "kind": "SYSTEM",
    "userId": null
  },
  "data": {
    "lease": {
      "id": "clx1lea001",
      "code": "A-0007",
      "status": "ACTIVE",
      "startDate": "2025-11-01T00:00:00.000Z",
      "endDate": "2026-10-31T00:00:00.000Z",
      "daysToEnd": 30,
      "monthlyRent": 3200000,
      "adminFee": 380000,
      "currency": "COP",
      "paymentDayOfMonth": 5,
      "propertyId": "clx1prop002",
      "tenantId": "clx1con002",
      "ownerId": "clx1con003",
      "managerId": "clx1usr001",
      "createdAt": "2025-10-28T19:00:00.000Z"
    },
    "contact": {
      "id": "clx1con002",
      "code": "C-0043",
      "firstName": "Camilo",
      "lastName": "Duarte",
      "fullName": "Camilo Duarte",
      "email": "camilo.duarte@example.com",
      "phone": "+573000000002",
      "source": "REFERRAL",
      "status": "WON",
      "type": "CLIENT",
      "score": 90,
      "ownerId": "clx1usr001",
      "preferredCity": "Medellín",
      "preferredType": "APARTMENT",
      "budget": 3200000,
      "currency": "COP",
      "tags": [
        "Arrendatario"
      ],
      "createdAt": "2025-11-02T13:00:00.000Z"
    },
    "property": {
      "id": "clx1prop002",
      "code": "P-0057",
      "title": "Apartamento en El Poblado cerca a la estación",
      "type": "APARTMENT",
      "transactionType": "RENT",
      "status": "RENTED",
      "price": null,
      "rentPrice": 3200000,
      "currency": "COP",
      "city": "Medellín",
      "neighborhood": "El Poblado",
      "address": "Cl 10 #43-20",
      "bedrooms": 2,
      "bathrooms": 2,
      "area": 68,
      "agentId": "clx1usr001",
      "createdAt": "2025-10-20T14:00:00.000Z"
    },
    "threshold": 30,
    "daysToEnd": 30
  }
}
```

rent_payment.overdue:

```
{
  "event": "rent_payment.overdue",
  "id": "5f3a0c1e-7d2b-4f7e-9a51-0b6c1d2e3f40",
  "type": "rent_payment.overdue",
  "timestamp": "2026-09-22T14:30:00.000Z",
  "organizationId": "clx1org001",
  "actor": {
    "kind": "SYSTEM",
    "userId": null
  },
  "data": {
    "rentPayment": {
      "id": "clx1rpy002",
      "period": "2026-10",
      "status": "OVERDUE",
      "totalAmount": 3580000,
      "paidAmount": null,
      "currency": "COP",
      "dueDate": "2026-10-05T00:00:00.000Z",
      "paidAt": null,
      "daysOverdue": 3,
      "leaseId": "clx1lea001",
      "tenantId": "clx1con002",
      "propertyId": "clx1prop002"
    },
    "lease": {
      "id": "clx1lea001",
      "code": "A-0007",
      "status": "ACTIVE",
      "startDate": "2025-11-01T00:00:00.000Z",
      "endDate": "2026-10-31T00:00:00.000Z",
      "daysToEnd": 23,
      "monthlyRent": 3200000,
      "adminFee": 380000,
      "currency": "COP",
      "paymentDayOfMonth": 5,
      "propertyId": "clx1prop002",
      "tenantId": "clx1con002",
      "ownerId": "clx1con003",
      "managerId": "clx1usr001",
      "createdAt": "2025-10-28T19:00:00.000Z"
    },
    "contact": {
      "id": "clx1con002",
      "code": "C-0043",
      "firstName": "Camilo",
      "lastName": "Duarte",
      "fullName": "Camilo Duarte",
      "email": "camilo.duarte@example.com",
      "phone": "+573000000002",
      "source": "REFERRAL",
      "status": "WON",
      "type": "CLIENT",
      "score": 90,
      "ownerId": "clx1usr001",
      "preferredCity": "Medellín",
      "preferredType": "APARTMENT",
      "budget": 3200000,
      "currency": "COP",
      "tags": [
        "Arrendatario"
      ],
      "createdAt": "2025-11-02T13:00:00.000Z"
    },
    "property": {
      "id": "clx1prop002",
      "code": "P-0057",
      "title": "Apartamento en El Poblado cerca a la estación",
      "type": "APARTMENT",
      "transactionType": "RENT",
      "status": "RENTED",
      "price": null,
      "rentPrice": 3200000,
      "currency": "COP",
      "city": "Medellín",
      "neighborhood": "El Poblado",
      "address": "Cl 10 #43-20",
      "bedrooms": 2,
      "bathrooms": 2,
      "area": 68,
      "agentId": "clx1usr001",
      "createdAt": "2025-10-20T14:00:00.000Z"
    },
    "daysOverdue": 3
  }
}
```

ticket.created:

```
{
  "event": "ticket.created",
  "id": "5f3a0c1e-7d2b-4f7e-9a51-0b6c1d2e3f40",
  "type": "ticket.created",
  "timestamp": "2026-09-22T14:30:00.000Z",
  "organizationId": "clx1org001",
  "actor": {
    "kind": "USER",
    "userId": "clx1usr001"
  },
  "data": {
    "ticket": {
      "id": "clx1tkt001",
      "number": 12,
      "code": "T-0012",
      "title": "No llegan las fotos al portal",
      "summary": "La clienta dice que la ficha P-0042 se ve sin fotos desde ayer.",
      "status": "PENDING",
      "priority": "HIGH",
      "channel": "WHATSAPP",
      "labels": [
        "Portales"
      ],
      "assignedToId": "clx1usr001",
      "assignedToName": "Andrés Mejía",
      "contactId": "clx1con001",
      "conversationId": "clx1cnv001",
      "linearIssueKey": null,
      "url": "https://www.bydomu.com/inbox/tickets/clx1tkt001",
      "resolvedAt": null,
      "createdAt": "2026-09-22T14:30:00.000Z",
      "updatedAt": "2026-09-22T14:30:00.000Z"
    },
    "contact": {
      "id": "clx1con001",
      "code": "C-0042",
      "firstName": "Laura",
      "lastName": "Restrepo",
      "fullName": "Laura Restrepo",
      "email": "laura.restrepo@example.com",
      "phone": "+573000000001",
      "source": "WEBSITE",
      "status": "QUALIFIED",
      "type": "CLIENT",
      "score": 72,
      "ownerId": "clx1usr001",
      "preferredCity": "Bogotá",
      "preferredType": "APARTMENT",
      "budget": 450000000,
      "currency": "COP",
      "tags": [
        "Compra",
        "Chapinero"
      ],
      "createdAt": "2026-09-20T15:04:00.000Z"
    }
  }
}
```

Los datos son inventados; la forma es la real. Los eventos .deleted solo traen id, nombre y código, porque el registro ya no existe.
