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

# Webhooks e eventos

> Receba lotes assinados e concilie eventos por meio de um cursor.

## Cadastre e teste um endpoint HTTPS

Cadastre o endpoint para a chave proprietária dos eventos. Armazene o `webhook_secret` retornado ao cadastrar a URL e evite registrar a resposta em logs compartilhados. A entrega começa com eventos novos após o cadastro. O teste envia um evento assinado `webhook.test`. Confira `delivered` e o registro do receptor depois de carregar o segredo no verificador.

```bash theme={null}
curl -fsS -X PUT "$INTERACTIVE_LAYERS_BASE/v1/keys/me/webhook" \
  -H "X-API-Key: $INTERACTIVE_LAYERS_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"url":"https://receiver.example/interactivelayers/events"}'

curl -fsS -X POST "$INTERACTIVE_LAYERS_BASE/v1/keys/me/webhook/test" \
  -H "X-API-Key: $INTERACTIVE_LAYERS_API_KEY"
```

## Verifique os bytes originais do corpo

Use `X-InteractiveLayers-Key-Id` para selecionar o segredo configurado. Leia `X-InteractiveLayers-Timestamp` e `X-InteractiveLayers-Signature`. A assinatura é o HMAC-SHA256 hexadecimal do timestamp, um ponto e os bytes exatos do corpo HTTP. Valide antes de decodificar o JSON. Durante a transição, os headers antigos `X-Clipma-*` podem acompanhar os atuais.

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


def verify(secret: str, timestamp: str, raw_body: bytes, signature: str) -> bool:
    if not re.fullmatch(r"[0-9]{1,12}", timestamp):
        return False
    if not re.fullmatch(r"[0-9a-f]{64}", signature):
        return False
    if abs(time.time() - int(timestamp)) > 300:
        return False
    signed_bytes = timestamp.encode("ascii") + b"." + raw_body
    expected = hmac.new(secret.encode("utf-8"), signed_bytes, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, signature)
```

O corpo tem a forma `{"events":[...]}`. Confirme o lote depois de armazená-lo de forma durável e deduplique por `id` do evento. Um lote com três falhas é ignorado. Para conciliar, consulte `GET /v1/events?since=0&types=break.signal,source.error` com `events:read`. Salve `next_since` mesmo após uma página vazia e use-o na próxima consulta com os mesmos filtros. `seq` indica a posição do cursor. Os tipos incluem `opportunity.detected`, `brand_safety.hold`, `break.announced`, `break.signal`, `break.decided` e `vod.scan.completed`. O evento de teste tem `seq: 0` e permite verificar o receptor. [Erros e novas tentativas](https://docs.interactivelayers.com/pt-br/errors.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.