Developer API

TPVStream API: webhooks

Get a notice on your server when there is a sale, a closure, a stock or order change.

On this page

With a webhook, the POS tells your server when something happens, instead of your application asking every minute. It needs the webhooks:manage right, plus the read right of each event.

Events

Event When Read right
ticket.created Sale paid, invoiced or corrected sales:read
closure.created Z closure done sales:read
product.updated Product created or changed (its online sheet too) catalog:read
stock.low A product falls below its minimum stock stock:read
order.status_changed A remote order changes status orders:read
client.updated Client created or changed clients:read

The POS looks for changes every 15 seconds. A new webhook starts when it is created: it does not get what happened before.

Create a webhook

curl -X POST https://api.tpvstream.com/<id>/v1/webhooks \
  -H "Authorization: Bearer tpv_live_…" \
  -H "Idempotency-Key: 41c7…" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://my-app.example.com/tpv/webhook","events":["ticket.created","stock.low"]}'

The answer holds the secret whsec_…. Keep it: it is only shown this once and is used to check the signature.

  • The address must be https, on port 443, with a public name. No redirects.
  • 10 webhooks at most per key.
  • GET /webhooks and GET /webhooks/{id} give the status (lastAt, lastResult, pending, failingSince). DELETE /webhooks/{id} deletes it.
  • POST /webhooks/{id}/test sends a webhook.test message to try it.

Address verification

Before the first message (then every 24 hours), your address receives:

{ "type": "webhook.verify", "challenge": "9f2c…" }

Answer with a 2xx status and the challenge value, as plain text or as {"challenge":"9f2c…"}. Otherwise nothing is sent: nobody can use the system to flood someone else's server.

The message

{ "id": "0b9f6c2e-…", "type": "ticket.created", "createdAt": "2026-11-27T12:33:52.000Z", "data": { "id": "1042" } }

The message holds only identifiers. For details, read the item with the API (GET /tickets/1042). No sensitive data travels in the notice.

Check the signature

Each message has the header:

X-TPV-Signature: t=1764247432,v1=5f8a…

v1 is the hex HMAC-SHA256 of "<t>.<raw body>" with your secret. Check the signature and refuse a t older than 5 minutes.

Node.js (Express):

const crypto = require('crypto');

app.post('/tpv/webhook', express.raw({ type: 'application/json' }), (req, res) => {
  const body = req.body.toString('utf8');
  const msg = JSON.parse(body);
  if (msg.type === 'webhook.verify') return res.json({ challenge: msg.challenge });

  const sig = Object.fromEntries((req.get('X-TPV-Signature') || '').split(',').map((p) => p.split('=')));
  const expected = crypto.createHmac('sha256', process.env.TPV_WEBHOOK_SECRET).update(`${sig.t}.${body}`).digest('hex');
  const fresh = Math.abs(Date.now() / 1000 - Number(sig.t)) < 300;
  const valid = sig.v1?.length === expected.length && crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(sig.v1));
  if (!fresh || !valid) {
    return res.sendStatus(401);
  }
  // Store msg.id: if you already handled it, ignore it.
  res.sendStatus(200);
});

PHP:

$body = file_get_contents('php://input');
$msg  = json_decode($body, true);
if (($msg['type'] ?? '') === 'webhook.verify') {
    header('Content-Type: application/json');
    exit(json_encode(['challenge' => $msg['challenge']]));
}
parse_str(str_replace(',', '&', $_SERVER['HTTP_X_TPV_SIGNATURE'] ?? ''), $sig);
$expected = hash_hmac('sha256', ($sig['t'] ?? '') . '.' . $body, getenv('TPV_WEBHOOK_SECRET'));
if (abs(time() - (int) ($sig['t'] ?? 0)) > 300 || ! hash_equals($expected, $sig['v1'] ?? '')) {
    http_response_code(401);
    exit;
}
// Store $msg['id']: if you already handled it, ignore it.
http_response_code(200);

Retries

  • Answer within a few seconds with a 2xx and do the work afterwards.
  • If your server fails, the message is sent again 8 times, from 30 seconds to 6 hours. Messages wait 7 days at most.
  • After 3 days of failures in a row, the webhook is turned off. The owner turns it on again in Settings › Cloud API.
  • A message can arrive more than once: ignore an id already handled.

Messages leave from api.tpvstream.com, never from the shop's network.

WhatsApp