Pular para o conteúdo principal

API de Webhooks

Configure webhooks para receber notificações sobre eventos.

Listar Webhooks​

GET /v1/webhooks

Resposta:

{
"success": true,
"webhooks": [
{
"id": "wh_abc123",
"url": "https://your-server.com/webhook",
"events": ["index.complete", "security.alert"],
"active": true,
"createdAt": "2024-01-10T08:00:00Z"
}
]
}

Criar Webhook​

POST /v1/webhooks

Corpo da Requisição:

{
"url": "https://your-server.com/webhook",
"events": ["index.complete", "security.alert"],
"secret": "seu-segredo-webhook"
}

Resposta:

{
"success": true,
"webhook": {
"id": "wh_xyz789",
"url": "https://your-server.com/webhook",
"events": ["index.complete", "security.alert"],
"active": true
}
}

Excluir Webhook​

DELETE /v1/webhooks/:id

Eventos Disponíveis​

EventoDescrição
index.startedA indexação começou
index.completeA indexação foi concluída com sucesso
index.failedA indexação falhou
security.alertNova vulnerabilidade de segurança encontrada
analysis.completeAnálise concluída

Payload do Webhook​

Todos os webhooks recebem um payload JSON:

{
"event": "index.complete",
"timestamp": "2024-01-15T10:30:00Z",
"project": {
"id": "proj_abc123",
"name": "my-app"
},
"data": {
"filesCount": 234,
"symbolsCount": 1847,
"duration": 45
}
}

Verificação de Assinaturas​

Webhooks incluem um cabeçalho de assinatura para verificação:

X-ArchiCore-Signature: sha256=abc123...

Verificação (Node.js):

const crypto = require('crypto');

function verifyWebhook(payload, signature, secret) {
const expected = crypto
.createHmac('sha256', secret)
.update(payload)
.digest('hex');

return crypto.timingSafeEqual(
Buffer.from(signature),
Buffer.from(`sha256=${expected}`)
);
}

Política de Tentativas​

Entregas de webhook falhadas são tentadas novamente:

  • Tentativa 1: Imediata
  • Tentativa 2: Após 1 minuto
  • Tentativa 3: Após 5 minutos
  • Tentativa 4: Após 30 minutos
  • Tentativa 5: Após 2 horas

Após 5 tentativas falhadas, o webhook é desativado.