Webhooks
Webhooks push shipment changes to your system in real time, so you don't have to poll the API. The most important case is carrier re-measurement: the carrier weighs and measures the parcel, the chargeable weight (desi) and price change, and a debt or refund is booked to your wallet. With shipment.measurement.adjusted you learn about it immediately.
Authentication: Webhook management endpoints (/v1/webhooks) use the same API key token as the rest of the API (Authorization: Bearer TOKEN). A webhook belongs to the API key that created it and only receives events of your own shipments.
How It Works
1. Create a webhook — POST /v1/webhooks with an HTTPS URL and the events you need. Save the secret from the response (shown once).
2. Receive events — cargopanel sends an HTTP POST with a JSON body to your URL. Events are sent asynchronously, after the shipment and wallet changes are committed.
3. Verify the signature — check X-Cargopanel-Signature with your secret before trusting the body.
4. Respond with 2xx quickly — any other response, a timeout (15s) or a redirect counts as a failure and is retried.
5. Deduplicate by eventId — retries resend the same event with the same eventId and identical body.
6. Fetch the latest state when needed — GET /v1/shipments/:id returns the current shipment.
Events
| Event | Description |
|---|---|
shipment.measurement.adjusted | The carrier measured the parcel and its weight (desi) differs from the previous measurement. Includes declared vs. measured weight, price difference and the wallet debt/refund. |
shipment.debt.adjusted | A debt or refund was booked to your wallet for a shipment after a carrier re-measurement. `debt.amount` > 0 is a charge, < 0 is a refund. |
shipment.status.updated | The shipment's tracking status changed. |
shipment.createdsoon | A shipment was created. Subscribable now; delivery will be enabled in an upcoming release. |
shipment.deliveredsoon | The shipment was delivered. Subscribable now; delivery will be enabled in an upcoming release. |
shipment.cancelledsoon | The shipment was cancelled. Subscribable now; delivery will be enabled in an upcoming release. |
Payload: shipment.measurement.adjusted
All new events use the same envelope: event, eventId, createdAt and data. shipment.debt.adjusted carries the same data object.
{
"event": "shipment.measurement.adjusted",
"eventId": "evt_5f2b9c1d7a3e4b6f8a0c2d1e",
"createdAt": "2026-11-10T10:30:00.000Z",
"data": {
"shipmentId": "12345678",
"trackingNumber": "123456789",
"carrier": "Yurtiçi Kargo",
"measurement": {
"declaredWeight": 3,
"measuredWeight": 5,
"previousMeasuredWeight": null,
"chargeableWeight": 5
},
"pricing": {
"originalPrice": 100,
"carrierTotalPrice": 145.5,
"difference": 45.5,
"currency": "TRY"
},
"debt": {
"amount": 45.5,
"totalDebt": 45.5,
"previousTotalDebt": 0,
"status": "charged"
}
}
}| Field | Description |
|---|---|
measurement.declaredWeight | Weight (desi) you declared when creating the shipment. Never changes. null for older shipments where it is not known. |
measurement.measuredWeight | New weight measured by the carrier. |
measurement.previousMeasuredWeight | Previous carrier measurement; null on the first measurement. |
measurement.chargeableWeight | Weight now used for billing (= measuredWeight). |
pricing.originalPrice | Price paid when the shipment was created. |
pricing.carrierTotalPrice | Latest total price calculated for the carrier measurement. |
pricing.difference | carrierTotalPrice − originalPrice. |
debt.amount | Amount booked to the wallet by THIS adjustment. Positive = charge, negative = refund. |
debt.totalDebt | Total extra charge for the shipment after this adjustment (previousTotalDebt + amount). |
debt.status | charged | refunded | unchanged |
Example sequence (declared 3 desi, paid 100 TRY): carrier measures 5 → amount: 45; later 6 → amount: 20 (total 65); later 5 again → amount: -20 (refund, total 45). The same measurement reported twice does not create a second event or wallet movement.
Payload: shipment.status.updated
Kept in its original (flat) format for existing integrations; an eventId field has been added.
{
"event": "shipment.status.updated",
"eventId": "evt_8c1d2e3f4a5b6c7d8e9f0a1b",
"shipmentId": "12345678",
"carrier": "UPS",
"trackingNumber": "1Z999AA10123456784",
"userId": "usr_xyz789",
"previousStatus": { "status": "...", "location": "Germany", "date": "2026-05-19T13:50:00+0300", "milestone": "in_transit" },
"currentStatus": { "status": "...", "location": "Germany", "date": "2026-05-22T12:14:00+0300", "milestone": "in_transit" },
"updatedAt": "2026-06-20T14:30:00.000Z"
}Request Headers
Content-Type | application/json |
X-Cargopanel-Event | Event type, e.g. shipment.measurement.adjusted |
X-Cargopanel-Event-Id | Unique event ID (same on every retry) — use it for idempotency. |
X-Cargopanel-Delivery-Id | Delivery ID; look it up with GET /v1/webhook-deliveries/:id. |
X-Cargopanel-Signature | sha256=<hex HMAC-SHA256 of the raw body with your webhook secret> |
X-Webhook-Event / X-Webhook-Delivery-Id / X-Webhook-Signature | Legacy headers kept for backward compatibility (signature without the sha256= prefix). |
Verifying the Signature
Compute HMAC-SHA256 over the raw request body (do not re-serialize the parsed JSON) with your webhook secret, prefix it with sha256= and compare it to X-Cargopanel-Signature using a constant-time comparison.
Node.js (Express)
import crypto from 'crypto';
import express from 'express';
const app = express();
// Use the RAW body: the signature is computed over the exact bytes we send.
app.post('/webhooks/cargopanel', express.raw({ type: 'application/json' }), (req, res) => {
const signature = req.header('X-Cargopanel-Signature') || '';
const expected = 'sha256=' + crypto
.createHmac('sha256', process.env.CARGOPANEL_WEBHOOK_SECRET)
.update(req.body)
.digest('hex');
const valid =
signature.length === expected.length &&
crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected));
if (!valid) return res.status(401).send('invalid signature');
const event = JSON.parse(req.body.toString('utf8'));
// Idempotency: the same eventId may arrive more than once (retries).
// if (await alreadyProcessed(event.eventId)) return res.sendStatus(200);
res.sendStatus(200); // answer fast, process asynchronously
});PHP
<?php
$payload = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_CARGOPANEL_SIGNATURE'] ?? '';
$expected = 'sha256=' . hash_hmac('sha256', $payload, getenv('CARGOPANEL_WEBHOOK_SECRET'));
if (!hash_equals($expected, $signature)) {
http_response_code(401);
exit('invalid signature');
}
$event = json_decode($payload, true);
http_response_code(200);Python
import hmac, hashlib, os
def verify(raw_body: bytes, signature: str) -> bool:
expected = "sha256=" + hmac.new(
os.environ["CARGOPANEL_WEBHOOK_SECRET"].encode(), raw_body, hashlib.sha256
).hexdigest()
return hmac.compare_digest(expected, signature or "")Retries
A delivery is attempted up to 5 times:
| Attempt | When |
|---|---|
| 1 | Immediately |
| 2 | 1 minute after attempt 1 |
| 3 | 5 minutes after attempt 2 |
| 4 | 30 minutes after attempt 3 |
| 5 | 2 hours after attempt 4 |
Retry times are minimums; a delivery may arrive slightly later. After the 5th failure the delivery is marked failed. You can always inspect attempts with GET /v1/webhooks/:id/deliveries. A failing webhook never affects your shipments or wallet.
Security
• Only public HTTPS URLs are accepted. Addresses that resolve to localhost, private / internal networks or cloud metadata services are blocked, both when you register the URL and on every delivery.
• Redirects (3xx) are not followed and count as a failed attempt.
• The secret is stored encrypted and is never returned again after creation or rotation.