Webhooks

Qué es

Lotus puede llamar a su servidor (HTTPS) cuando cambian datos sincronizados: productos, contactos o ventas. Usted registra la URL en Integraciones → Partner API → Webhooks.

Esto es independiente de la Partner API Bearer (ltk_live_…): la key sirve para que usted llame a Lotus; el webhook es para que Lotus llame a usted.

Configuración

  1. En Lotus: Integraciones → Partner API.
  2. Sección Webhooks: URL https://…, opcionalmente un secreto compartido, y Habilitado.
  3. Probar envía un evento webhook.test.
  4. Su endpoint debe responder 2xx en pocos segundos.

Entrega

HeaderValor
Content-Typeapplication/json
User-AgentLotus-Webhooks/1.0
X-Lotus-Eventtipo del evento (p. ej. sale.updated)
X-Lotus-Deliveryid del evento (evt_…)
X-Lotus-Signaturesolo si configuró secreto: sha256=<hmac_hex_del_body>

Firma (si hay secreto): HMAC-SHA256 del body crudo con el secreto; prefijo sha256=.

Reintentos: cola con backoff (varios intentos). Use id / X-Lotus-Delivery para idempotencia.

Eventos MVP

TipoCuándo
product.updatedUpsert/patch/deactivate Partner o pull ERP de productos
contact.updatedUpsert Partner o pull de clientes ERP
sale.updatedUpsert Partner o pull de facturas / anulación (VOID)
webhook.testBotón Probar en Integraciones

Ejemplo de payload

{
  "id": "evt_01hxyz…",
  "type": "sale.updated",
  "createdAt": "2026-10-21T22:00:00.000Z",
  "accountNumber": 1001,
  "data": {
    "saleId": "uuid",
    "contactId": "uuid",
    "externalId": "fv-900",
    "status": "POSTED",
    "provider": "ERP_SIIGO",
    "created": false
  }
}

El campo data varía por tipo; siempre incluye identificadores útiles (externalId, ids Lotus, provider).

Verificación HMAC (Node)

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

function verify(secret, rawBody, header) {
  const expected = "sha256=" + createHmac("sha256", secret).update(rawBody).digest("hex");
  const a = Buffer.from(expected);
  const b = Buffer.from(header || "");
  return a.length === b.length && timingSafeEqual(a, b);
}

Más eventos y filtros por suscripción se irán añadiendo; el contrato de envoltorio (id, type, createdAt, accountNumber, data) se mantiene estable.