> ## Documentation Index
> Fetch the complete documentation index at: https://docs.topsort.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Uso de webhooks

export const LastUpdatedEs = ({date}) => {
  const label = "Última actualización:";
  return <>
      <style>{`
        .last-updated-component {
          display: inline-flex;
          align-items: center;
          gap: 8px;
          padding: 10px 16px;
          border-radius: 8px;
          margin-top: 12px;
          margin-bottom: 16px;
          font-size: 14px;
          background-color: rgba(0, 0, 0, 0.05);
          border: 1px solid rgba(0, 0, 0, 0.12);
          color: rgba(0, 0, 0, 0.75);
          line-height: 1;
        }

        .last-updated-component svg {
          flex-shrink: 0;
          vertical-align: middle;
        }

        .last-updated-component span {
          display: inline-flex !important;
          align-items: center !important;
          line-height: 1 !important;
        }

        [data-theme="dark"] .last-updated-component {
          background-color: #3a3a3a;
          border: 2px solid #888888;
          color: #ffffff;
        }

        [data-theme="dark"] .last-updated-component svg {
          stroke: #ffffff;
        }
      `}</style>
      <div className="last-updated-component">
        <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
          <circle cx="12" cy="12" r="10" />
          <polyline points="12 6 12 12 16 14" />
        </svg>
        <span>
          <strong style={{
    fontWeight: 600
  }}>{label}</strong> 
          <time dateTime={date}>{date}</time>
        </span>
      </div>
    </>;
};

<div style={{textAlign: 'justify', marginBottom: '1.5rem'}}>
  Los webhooks proporcionan notificaciones en tiempo real sobre eventos como la creación, actualización o eliminación de campañas. Para recibir estas notificaciones, debe especificar un URL de acceso público capaz de recibir solicitudes POST HTTP.
</div>

## Cómo funciona

<div style={{textAlign: 'justify', marginBottom: '1.5rem'}}>
  Cuando se produce un evento, se envía una solicitud POST HTTP con los detalles del evento a su URL especificado. Su URL debe devolver un código de estado HTTP 2xx para las solicitudes exitosas.
</div>

<div style={{textAlign: 'justify', marginBottom: '1.5rem'}}>
  Los webhooks se crean mediante la función Crear webhook (API), donde se define el evento desencadenante utilizando el campo de canal. Solo se permite un webhook por canal.
</div>

### Reintentos y validación

<div style={{textAlign: 'justify', marginBottom: '1.5rem'}}>
  Si su webhook URL no está disponible, intentaremos enviar la solicitud hasta 5 veces en 1 minuto, utilizando un retroceso exponencial. Los reintentos solo se producen para los códigos de estado 5xx o 429 HTTP.
</div>

<div style={{textAlign: 'justify', marginBottom: '1.5rem'}}>
  Para garantizar la autenticidad e integridad de las entregas de webhook, debe validar la firma. Topsort genera una firma utilizando su secreto de webhook y la carga útil del evento, incluyéndola en el encabezado X-TS-Signature-256 HTTP.
</div>

<div style={{textAlign: 'justify', marginBottom: '1.5rem'}}>
  Puedes establecer tu secreto de webhook durante la creación; de lo contrario, se generará uno automáticamente. Guarda tu secreto de forma segura.
</div>

<div style={{textAlign: 'justify', marginBottom: '1.5rem'}}>
  Topsort utiliza el resumen hexadecimal HMAC (que comienza con sha256=) para calcular la firma. Debe recalcular el hash en su servidor y compararlo con la cabecera X-TS-Signature-256 para verificar la firma.
</div>

### Ejemplo de verificación de firma

```python theme={null}
import hmac
import hashlib

secret = "my-webhook-secret"
request = ... # incoming request from the webhook delivery

signature = hmac.new(
    key=secret.encode(),
    msg=await request.body(),
    digestmod=hashlib.sha256,
).hexdigest()

expected_signature = "sha256=" + signature
incoming_signature = request.headers["X-TS-Signature-256"]

if not hmac.compare_digest(incoming_signature, expected_signature):
    # The signature is not valid, do not process the delivery
else:
    # The signature is valid, process the delivery
```

***

<LastUpdatedEs date="2025-11-18" />
