API Webhooks
Configura i webhooks per ricevere notifiche sugli eventi.
Elenco Webhooks
GET /v1/webhooks
Risposta:
{
"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"
}
]
}
Crea Webhook
POST /v1/webhooks
Corpo della Richiesta:
{
"url": "https://your-server.com/webhook",
"events": ["index.complete", "security.alert"],
"secret": "il-tuo-segreto-webhook"
}
Risposta:
{
"success": true,
"webhook": {
"id": "wh_xyz789",
"url": "https://your-server.com/webhook",
"events": ["index.complete", "security.alert"],
"active": true
}
}
Elimina Webhook
DELETE /v1/webhooks/:id
Eventi Disponibili
| Evento | Descrizione |
|---|---|
index.started | L'indicizzazione è iniziata |
index.complete | L'indicizzazione è stata completata con successo |
index.failed | L'indicizzazione è fallita |
security.alert | Nuova vulnerabilità di sicurezza trovata |
analysis.complete | Analisi completata |
Payload del Webhook
Tutti i webhooks ricevono un 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 delle Firme
I webhooks includono un header di firma per la verifica:
X-ArchiCore-Signature: sha256=abc123...
Verifica (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}`)
);
}
Politica di Retry
Le consegne webhook fallite vengono ritentate:
- Tentativo 1: Immediato
- Tentativo 2: Dopo 1 minuto
- Tentativo 3: Dopo 5 minuti
- Tentativo 4: Dopo 30 minuti
- Tentativo 5: Dopo 2 ore
Dopo 5 tentativi falliti, il webhook viene disabilitato.