Webhooks y eventos en tiempo real
Busqueda objetivo: "webhooks api transporte", "eventos tiempo real carga mercancias"
Registrar webhook
bash
curl -X POST "https://api.pro.cargoffer.com/api/webhook" \
-H "Authorization: Bearer *** \
-H "Content-Type: application/json" \
-d '{
"url": "https://tu-sistema.com/webhook",
"events": [
"contract.signed",
"payment.received",
"delivery.completed",
"document.signed"
]
}'Eventos disponibles
| Evento | Descripcion | Payload incluye |
|---|---|---|
auction.created | Nueva subasta | serviceCode, origen, destino, peso |
auction.bid | Oferta recibida | serviceCode, transportista, importe |
auction.accepted | Oferta aceptada | serviceCode, contrato |
contract.signed | Contrato firmado | serviceCode, importe, cliente |
payment.received | Pago confirmado | invoiceId, importe, metodo |
delivery.completed | Entrega realizada | deliveryId, firma, fecha |
document.signed | eCMR firmado | documentId, firmante |
Verificar payload
Siempre verifica la firma del webhook:
python
import hashlib, hmac
def verify_webhook(payload, signature, secret):
expected = hmac.new(
secret.encode(), payload, hashlib.sha256
).hexdigest()
return hmac.compare_digest(expected, signature)