Saltar al contenido principal
API Documentation

Webhooks

Los webhooks permiten que WorkFlows notifique a tus sistemas en tiempo real cuando ocurren eventos. Configura endpoints HTTPS para recibir payloads firmados con HMAC-SHA256.

Crear un webhook

Crea webhooks desde Dashboard → Desarrolladores → Webhooks o via API. Selecciona los eventos que quieres recibir y proporciona un endpoint HTTPS.

Crear webhook via API
curl -X POST https://www.workflows.com.es/api/v1/webhooks \
  -H "Authorization: Bearer wf_live_abc123..." \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Slack Alerts",
    "url": "https://my-server.com/webhooks/workflows",
    "events": ["alert.created", "alert.critical", "alert.resolved"]
  }'
El signing secret solo se retorna en la respuesta de creación. Guárdalo de forma segura — lo necesitarás para verificar las firmas de los payloads.

Formato del payload

Cada delivery envía un POST con los siguientes headers y body:

Headers
Content-Type: application/json
X-WorkFlows-Signature: sha256=<hex digest>
X-WorkFlows-Event: alert.created
Body (JSON)
{
  "event": "alert.created",
  "orgId": "org_abc123",
  "timestamp": "2026-05-19T16:30:00.000Z",
  "data": {
    "id": "alert_xyz789",
    "title": "Inventario crítico: Materia Prima A",
    "severity": "critical",
    "status": "active",
    "projectId": "proj_def456",
    "area": "Inventario",
    "createdAt": "2026-05-19T16:30:00.000Z"
  }
}

Verificar firmas

Cada payload incluye una firma HMAC-SHA256 en el header X-WorkFlows-Signature. Siempre verifica la firma antes de procesar el payload para asegurar que proviene de WorkFlows.

Node.js
import crypto from "crypto";

function verifySignature(payload, signature, secret) {
  const expected = "sha256=" +
    crypto.createHmac("sha256", secret)
      .update(payload)
      .digest("hex");

  return crypto.timingSafeEqual(
    Buffer.from(signature),
    Buffer.from(expected)
  );
}

// En tu endpoint:
app.post("/webhooks/workflows", (req, res) => {
  const signature = req.headers["x-workflows-signature"];
  const isValid = verifySignature(
    JSON.stringify(req.body),
    signature,
    process.env.WORKFLOWS_WEBHOOK_SECRET
  );

  if (!isValid) return res.status(401).send("Invalid signature");

  // Procesar el evento...
  const { event, data } = req.body;
  console.log(`Evento recibido: ${event}`, data);

  res.status(200).send("OK");
});
Python
import hmac
import hashlib

def verify_signature(payload: bytes, signature: str, secret: str) -> bool:
    expected = "sha256=" + hmac.new(
        secret.encode(),
        payload,
        hashlib.sha256
    ).hexdigest()
    return hmac.compare_digest(signature, expected)

# En tu endpoint (Flask):
@app.route("/webhooks/workflows", methods=["POST"])
def handle_webhook():
    signature = request.headers.get("X-WorkFlows-Signature", "")
    if not verify_signature(request.data, signature, WEBHOOK_SECRET):
        return "Invalid signature", 401

    event = request.json["event"]
    data = request.json["data"]
    # Procesar...
    return "OK", 200
Usa timingSafeEqual (Node.js) o hmac.compare_digest (Python) para evitar ataques de timing.

Eventos disponibles

Suscríbete solo a los eventos que necesitas. Cada webhook puede escuchar múltiples eventos.

Alerts

alert.createdSe creó una nueva alerta
alert.acknowledgedUna alerta fue reconocida
alert.assignedUna alerta fue asignada a un usuario
alert.resolvedUna alerta fue resuelta
alert.criticalSe creó una alerta de severidad crítica
alert.deletedUna alerta fue eliminada

Projects

project.createdSe creó un nuevo proyecto
project.updatedUn proyecto fue actualizado
project.deletedUn proyecto fue eliminado

Users

user.invitedUn usuario fue invitado a la organización
user.joinedUn usuario aceptó la invitación
user.activatedUn usuario fue activado
user.deactivatedUn usuario fue desactivado

Data

csv.uploadedSe subió un archivo CSV/Excel

Connections

db_connection.createdSe creó una conexión a base de datos
db_connection.updatedUna conexión fue actualizada
db_connection.deletedUna conexión fue eliminada

Queries

query.completedUna consulta de IA terminó
query.deletedUn historial de consulta fue eliminado

API Keys

api_key.createdSe creó una nueva API key
api_key.deletedUna API key fue eliminada

Webhooks

webhook.createdSe creó un nuevo webhook
webhook.enabledUn webhook fue habilitado
webhook.disabledUn webhook fue deshabilitado
webhook.deletedUn webhook fue eliminado

Reintentos

Si tu endpoint no responde con un status 2xx en 10 segundos, WorkFlows reintentará con backoff exponencial hasta 5 intentos:

IntentoEsperaTiempo acumulado
1Inmediato0 min
21 minuto1 min
35 minutos6 min
415 minutos21 min
530 minutos51 min

Después de 5 intentos fallidos, el delivery se marca como fallido. Puedes ver el historial de deliveries en Dashboard → Desarrolladores → Webhooks → Deliveries o via API con GET /api/v1/webhooks/{id}/deliveries.

Buenas prácticas

  • Responde rápido — retorna 200 lo antes posible y procesa el evento de forma asíncrona.
  • Verifica siempre la firma — no proceses payloads sin validar X-WorkFlows-Signature.
  • Idempotencia — tu endpoint puede recibir el mismo evento más de una vez (reintentos). Usa el data.id para deduplicar.
  • Usa HTTPS — WorkFlows solo envía webhooks a endpoints HTTPS por seguridad.