cargopanel logocargopanel for developers

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

EventDescription
shipment.measurement.adjustedThe 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.adjustedA 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.updatedThe shipment's tracking status changed.
shipment.createdsoonA shipment was created. Subscribable now; delivery will be enabled in an upcoming release.
shipment.deliveredsoonThe shipment was delivered. Subscribable now; delivery will be enabled in an upcoming release.
shipment.cancelledsoonThe 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"
    }
  }
}
FieldDescription
measurement.declaredWeightWeight (desi) you declared when creating the shipment. Never changes. null for older shipments where it is not known.
measurement.measuredWeightNew weight measured by the carrier.
measurement.previousMeasuredWeightPrevious carrier measurement; null on the first measurement.
measurement.chargeableWeightWeight now used for billing (= measuredWeight).
pricing.originalPricePrice paid when the shipment was created.
pricing.carrierTotalPriceLatest total price calculated for the carrier measurement.
pricing.differencecarrierTotalPrice − originalPrice.
debt.amountAmount booked to the wallet by THIS adjustment. Positive = charge, negative = refund.
debt.totalDebtTotal extra charge for the shipment after this adjustment (previousTotalDebt + amount).
debt.statuscharged | 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-Typeapplication/json
X-Cargopanel-EventEvent type, e.g. shipment.measurement.adjusted
X-Cargopanel-Event-IdUnique event ID (same on every retry) — use it for idempotency.
X-Cargopanel-Delivery-IdDelivery ID; look it up with GET /v1/webhook-deliveries/:id.
X-Cargopanel-Signaturesha256=<hex HMAC-SHA256 of the raw body with your webhook secret>
X-Webhook-Event / X-Webhook-Delivery-Id / X-Webhook-SignatureLegacy 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:

AttemptWhen
1Immediately
21 minute after attempt 1
35 minutes after attempt 2
430 minutes after attempt 3
52 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.