Webhooks
Webhooks
Instead of polling, let Rigsight call your server. Every event is an HTTPS POST with a JSON body, signed with your endpoint's secret so you can prove it came from Rigsight.
Setting up an endpoint
Create an endpoint with POST /v1/webhooks (see the API reference), choosing which events it receives. The response contains the signing secret once; store it in your secrets manager. Endpoints must be public HTTPS URLs.
Events
| Event | Sent when |
|---|---|
| pti.completed | Analysis of a PTI has finished, whatever the status (PASS, NEEDS_REPAIR or OUT_OF_SERVICE). |
| pti.out_of_service | A completed PTI has at least one critical defect and the AI recommends OUT_OF_SERVICE. Sent in addition to pti.completed, so you can route it to an on-call channel. |
| pti.reviewed | A person recorded a decision on a PTI (through the API, the Rigsight app or the embed agent). |
| defect.recurring | A defect was detected again on the same truck before a repair was certified. |
pti.completed
Analysis of a PTI has finished, whatever the status (PASS, NEEDS_REPAIR or OUT_OF_SERVICE).
{
"event": "pti.completed",
"pti_id": "pti_4a11c0e2",
"truck": { "id": "trk_12", "unit_number": "1045" },
"type": "pre_trip",
"status": "NEEDS_REPAIR",
"summary": "Right marker lamp is not working. No critical defects.",
"defects": [
{
"component": "right side marker lamp",
"severity": "minor",
"description": "Lamp not illuminated",
"recurring": false
}
],
"unclear_components": [],
"report_url": "https://app.rigsight.uz/ptis/pti_4a11c0e2",
"completed_at": "2026-11-28T06:31:09Z",
"requires_human_review": true
}pti.out_of_service
A completed PTI has at least one critical defect and the AI recommends OUT_OF_SERVICE. Sent in addition to pti.completed, so you can route it to an on-call channel.
{
"event": "pti.out_of_service",
"pti_id": "pti_9f2c…",
"truck": { "id": "trk_12", "unit_number": "1045" },
"status": "OUT_OF_SERVICE",
"defects": [
{
"component": "left front tire",
"severity": "critical",
"description": "Tread below 4/32\"",
"recurring": false
}
],
"report_url": "https://app.rigsight.uz/ptis/pti_9f2c…",
"requires_human_review": true
}pti.reviewed
A person recorded a decision on a PTI (through the API, the Rigsight app or the embed agent).
{
"event": "pti.reviewed",
"pti_id": "pti_9f2c…",
"truck": { "id": "trk_12", "unit_number": "1045" },
"status": "OUT_OF_SERVICE",
"review": {
"decision": "oos",
"user": "safety@fleet.example",
"comment": "Confirmed with tread gauge. Tire replacement booked.",
"created_at": "2026-11-28T09:21:30Z"
},
"report_url": "https://app.rigsight.uz/ptis/pti_9f2c…"
}defect.recurring
A defect was detected again on the same truck before a repair was certified.
{
"event": "defect.recurring",
"defect_id": "def_7782",
"pti_id": "pti_9f2c…",
"truck": { "id": "trk_12", "unit_number": "1045" },
"component": "axle 2 right brake chamber",
"severity": "major",
"description": "Possible air leak: pushrod stroke indicator visible",
"occurrences": 3,
"first_seen_at": "2026-11-21T06:40:12Z",
"report_url": "https://app.rigsight.uz/ptis/pti_9f2c…",
"requires_human_review": true
}Human review is always required
requires_human_review: true. Use pti.out_of_service to alert a person, not to ground a truck automatically. Act on pti.reviewed for the final decision.Request headers
| Header | Description |
|---|---|
X-Rigsight-Signature | Signature in the form sha256=<hex>. |
X-Rigsight-Event | Event name, e.g. pti.out_of_service. |
X-Rigsight-Delivery | Unique delivery id (dlv_…). Stays the same across retries of the same delivery. |
X-Rigsight-Timestamp | Unix time in seconds when this attempt was signed. |
Content-Type | application/json; charset=utf-8 |
User-Agent | Rigsight-Webhooks/1 |
POST /hooks/rigsight HTTP/1.1
Host: tms.example.com
Content-Type: application/json; charset=utf-8
X-Rigsight-Event: pti.out_of_service
X-Rigsight-Delivery: dlv_5e0c9a71
X-Rigsight-Timestamp: 1795857412
X-Rigsight-Signature: sha256=3f9a1c…e07b
{"event":"pti.out_of_service","pti_id":"pti_9f2c…", …}Verifying signatures
Always verify a delivery before trusting it:
- Read
X-Rigsight-Timestampand reject the request if it is more than 5 minutes away from your clock. - Build the string
{timestamp}.{raw_body}using the exact raw request body bytes. - Compute HMAC-SHA256 of it with the endpoint secret, hex-encode it and prefix
sha256=. - Compare with
X-Rigsight-Signatureusing a constant-time comparison.
import crypto from "node:crypto";
import express from "express";
const app = express();
const SECRET = process.env.RIGSIGHT_WEBHOOK_SECRET; // whsec_…
// Use the RAW body: re-serialised JSON will not match the signature.
app.post("/hooks/rigsight", express.raw({ type: "application/json" }), (req, res) => {
const timestamp = req.get("X-Rigsight-Timestamp") ?? "";
const signature = req.get("X-Rigsight-Signature") ?? "";
// 1. Reject old or missing timestamps (replay protection, 5 minutes).
const age = Math.abs(Date.now() / 1000 - Number(timestamp));
if (!/^\d+$/.test(timestamp) || age > 300) return res.status(400).send("stale");
// 2. HMAC-SHA256 of "{timestamp}.{raw_body}" with the endpoint secret.
const signed = Buffer.concat([Buffer.from(timestamp + "."), req.body]);
const expected = "sha256=" + crypto.createHmac("sha256", SECRET).update(signed).digest("hex");
// 3. Constant-time comparison.
const a = Buffer.from(signature);
const b = Buffer.from(expected);
if (a.length !== b.length || !crypto.timingSafeEqual(a, b)) return res.status(401).send("bad signature");
// 4. Acknowledge fast, process asynchronously, de-duplicate by delivery id.
const deliveryId = req.get("X-Rigsight-Delivery");
const event = JSON.parse(req.body.toString("utf8"));
queue.add({ deliveryId, event });
res.sendStatus(200);
});import hashlib
import hmac
import os
import time
from flask import Flask, abort, request
app = Flask(__name__)
SECRET = os.environ["RIGSIGHT_WEBHOOK_SECRET"].encode() # whsec_…
@app.post("/hooks/rigsight")
def rigsight_hook():
raw = request.get_data() # raw bytes, before any JSON parsing
timestamp = request.headers.get("X-Rigsight-Timestamp", "")
signature = request.headers.get("X-Rigsight-Signature", "")
# 1. Replay protection: reject timestamps older than 5 minutes.
if not timestamp.isdigit() or abs(time.time() - int(timestamp)) > 300:
abort(400)
# 2. HMAC-SHA256 of "{timestamp}.{raw_body}".
digest = hmac.new(SECRET, timestamp.encode() + b"." + raw, hashlib.sha256).hexdigest()
# 3. Constant-time comparison.
if not hmac.compare_digest(signature, "sha256=" + digest):
abort(401)
# 4. Acknowledge fast; process in a background job keyed by delivery id.
enqueue(request.headers["X-Rigsight-Delivery"], request.get_json())
return "", 200<?php
$secret = getenv("RIGSIGHT_WEBHOOK_SECRET"); // whsec_…
$raw = file_get_contents("php://input"); // raw body
$timestamp = $_SERVER["HTTP_X_RIGSIGHT_TIMESTAMP"] ?? "";
$signature = $_SERVER["HTTP_X_RIGSIGHT_SIGNATURE"] ?? "";
// 1. Replay protection: reject timestamps older than 5 minutes.
if (!ctype_digit($timestamp) || abs(time() - (int) $timestamp) > 300) {
http_response_code(400);
exit;
}
// 2. HMAC-SHA256 of "{timestamp}.{raw_body}".
$expected = "sha256=" . hash_hmac("sha256", $timestamp . "." . $raw, $secret);
// 3. Constant-time comparison.
if (!hash_equals($expected, $signature)) {
http_response_code(401);
exit;
}
// 4. Acknowledge fast; process later, de-duplicated by delivery id.
$deliveryId = $_SERVER["HTTP_X_RIGSIGHT_DELIVERY"] ?? "";
enqueue($deliveryId, json_decode($raw, true));
http_response_code(200);Common mistake
Responding and retries
- Respond with any
2xxstatus within 10 seconds. Do heavy work in a background job after acknowledging. - Any other status, a timeout or a connection error counts as a failure and is retried.
- Retries use exponential backoff: after 1 min, 5 min, 30 min, 2 h, 6 h and 24 h — 6 attempts in total after the first. Each attempt is freshly signed with a new timestamp.
- Endpoints that keep failing for 3 days are automatically deactivated and fleet admins are emailed.
- Events are not guaranteed to arrive in order; use timestamps in the payload and re-fetch the PTI when in doubt.
Delivery log
Every attempt is recorded with its delivery id, event, HTTP status, response time and the first 1 KB of your response body. The log is kept for 30 days and is visible in the Rigsight app; failed deliveries can be resent from there.
Idempotency
Because of retries, the same event can be delivered more than once. Store X-Rigsight-Delivery ids you have processed (for example in a table with a unique index) and skip duplicates. A delivery id is unique per event and endpoint and does not change between retries.
Testing tips
- Use a
rs_test_…key: sandbox PTIs fire real, signed webhooks to the endpoints registered with that key. - During local development, expose your server with a tunnel (for example ngrok or Cloudflare Tunnel) and register the tunnel URL as a test endpoint.
- Unit-test your verifier with a known secret, timestamp and body, including a tampered body and a timestamp older than 5 minutes.
- Return 500 on purpose once to watch a retry arrive with the same delivery id.