Skip to content

Webhooks

Receiving events

With webhooks Wasil calls your server the moment something happens: a package is logged, shipped, delivered; a customer's US address is ready. You stop asking the API "anything new?".

Setting it up

  1. Build an address on your server that accepts POST requests, for example https://shop.example.com/wasil/webhook.
  2. On the portal open Account → Webhooks and save that address.
  3. Copy the signing secret (it starts with whsec_). It is shown once.
  4. Press Send a test event and check that your server received it and that the signature verifies.

The address must be public and start with https://. Addresses on private networks, on localhost, or with a user name and password in them are refused. One address per partner account.

What Wasil sends

A delivery
POST /wasil/webhook HTTP/1.1
Host: shop.example.com
Content-Type: application/json
User-Agent: Wasil-Webhooks/1.0
X-Wasil-Event: package.status_changed
X-Wasil-Delivery: evt_01j9z3k8w2m4n6p8q0r2s4t6v8
X-Wasil-Signature: sha256=6f1c0a5d9e4b8f2a7c3d1e0b9a8f7c6d5e4b3a2f1c0d9e8b7a6f5c4d3e2b1a0f

{
  "id": "evt_01j9z3k8w2m4n6p8q0r2s4t6v8",
  "type": "package.status_changed",
  "mode": "live",
  "created_at": "2026-10-03T14:20:11+03:00",
  "data": { "id": "WPger10005254CS3", "status": "on the way", "...": "..." }
}
PartMeaning
X-Wasil-EventThe event type, the same as type in the body.
X-Wasil-DeliveryThe event id, the same as id in the body. It stays the same when a delivery is retried.
X-Wasil-Signaturesha256= followed by the HMAC-SHA256 of the raw body, keyed with your signing secret, in hexadecimal.
idUnique per event. Use it to recognise an event you have already handled.
typeWhat happened. See the event reference.
modelive, or sandbox for an event from the sandbox.
created_atWhen it happened.
dataThe package or customer, in the same shape the API returns it.

Check the signature

Anyone can send a request to your address. The signature proves a request comes from Wasil and that the body was not changed on the way. Compute the HMAC over the raw body, exactly as received (before your framework parses the JSON), and compare it with the header using a constant-time comparison.

PHP
<?php
$secret    = getenv('WASIL_WEBHOOK_SECRET');           // whsec_...
$body      = file_get_contents('php://input');          // the raw body, before any parsing
$signature = $_SERVER['HTTP_X_WASIL_SIGNATURE'] ?? '';

$expected = 'sha256=' . hash_hmac('sha256', $body, $secret);

if (!hash_equals($expected, $signature)) {
    http_response_code(401);
    exit;
}

$event = json_decode($body, true);

// Answer first, work afterwards: queue the event, then return 2xx.
if (!already_handled($event['id'])) {
    enqueue($event);
}

http_response_code(204);
Node.js (Express)
import crypto from 'node:crypto';
import express from 'express';

const app = express();

// express.raw keeps the body exactly as it was sent
app.post('/wasil/webhook', express.raw({ type: 'application/json' }), (req, res) => {
  const expected = 'sha256=' + crypto
    .createHmac('sha256', process.env.WASIL_WEBHOOK_SECRET)
    .update(req.body)
    .digest('hex');
  const given = req.get('X-Wasil-Signature') || '';

  const ok = expected.length === given.length &&
    crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(given));
  if (!ok) return res.sendStatus(401);

  const event = JSON.parse(req.body);
  queue.add(event);          // handle it after answering
  res.sendStatus(204);
});
Python (Flask)
import hashlib, hmac, os
from flask import Flask, request

app = Flask(__name__)

@app.post("/wasil/webhook")
def wasil_webhook():
    body = request.get_data()                      # raw bytes
    expected = "sha256=" + hmac.new(
        os.environ["WASIL_WEBHOOK_SECRET"].encode(), body, hashlib.sha256
    ).hexdigest()

    if not hmac.compare_digest(expected, request.headers.get("X-Wasil-Signature", "")):
        return "", 401

    enqueue(request.get_json())                    # handle it after answering
    return "", 204

How to answer

  • Answer with any 2xx status within 10 seconds. The body of your answer is ignored.
  • Do the real work after answering: store the event or put it on a queue, answer, then process it.
  • A redirect (3xx) is not followed and counts as a failure. Save the final address on the portal.

When a delivery fails

If your server does not answer 2xx in time, the delivery is retried after 1 minute, 5 minutes, 30 minutes, 2 hours and 12 hours. After those five retries the event is given up. The portal shows every event with its status, the number of attempts and your server's last answer.

  • Twenty failures in a row pause your address: Wasil stops calling it and the portal says why. Events are still kept for you. Fix your server and press Resume deliveries; everything waiting is sent at once.
  • An event that could not be delivered within 3 days is given up. Catch up on anything you missed with GET /v1/packages?updated_since=….
  • Delivery records are kept for 30 days; the portal shows the most recent ones.

Three rules for a reliable receiver

  1. Expect an event more than once. If your 2xx answer is lost on the way, the event comes again with the same id. Keep the ids you have handled and skip repeats.
  2. Do not rely on the order. A retried event can arrive after a newer one. data carries the status at the time of the event; when in doubt, read the package from the API.
  3. Keep the secret secret. If it may have leaked, make a new one on the portal; the old one stops working at once, so update your server straight away.

How fast

Events are normally sent within a minute of the moment they happen.