Overview
When an event happens, Ruang IoT sends a JSON POST to your https:// address. Every delivery is signed, logged (status, HTTP code, duration, failure reason) and retried automatically when it fails. A webhook can subscribe to events, and can also be chosen as a Send webhook action in Alarms & Automation.
Creating a webhook
- Open the account menu → API & Webhooks (Personal workspace owner or Institution manager).
- Under Webhooks, enter a name and the receiver address (
https://…), choose events, and optionally limit it to specific projects. - Copy the signing secret (
whsec_…), shown once, and store it in your receiver. - Click Send test: your receiver gets a
pingevent, and the result appears in the Delivery log.
Events
| Event | Sent when | Data |
|---|---|---|
alert.triggered |
An Alarms & Automation rule becomes Active (or a momentary event: ON/OFF change, schedule) | rule, event, device, variable, message |
alert.recovered |
The alarm recovers | as above, with resolved_at and resolve_value |
device.online |
A device comes back online (checked every minute) | device, status, previous_status, last_seen_at |
device.inactive |
A device becomes inactive | as above |
data.received |
New Sensor/Status values arrive over MQTT or the REST API — collected per device for 10 seconds, then sent once with the latest value of every variable | device, values[] (key, value, unit, received_at), source (mqtt, http_api or mixed) |
ping |
The Send test button | message |
Request body
{
"id": "0f6c7d0e-6a41-4c5f-9a43-2b0b2f8e5a11",
"type": "alert.triggered",
"created_at": "2026-11-21T08:00:05+07:00",
"test": false,
"workspace": { "id": "7b1d0c3e-2f4a-4e8b-9d61-5a7c2e9f0b34" },
"project": { "id": "PROJECT_ID", "name": "Smart Garden" },
"data": {
"rule": { "id": "…", "name": "Temperature too high" },
"event": { "id": "…", "status": "active", "severity": "warning", "trigger_type": "numeric",
"trigger_value": "36.4", "resolve_value": null,
"started_at": "2026-11-21T08:00:04+07:00", "resolved_at": null },
"device": { "id": "ESP32KBN01", "name": "Garden ESP32" },
"variable": { "key": "temperature", "name": "Temperature", "unit": "°C" },
"message": "Alarm: Temperature too high (36.4 °C)"
}
}
All times are in WIB (ISO 8601, +07:00). test is true for Send test and Test rule. The full specification of every event is in the webhooks section of the OpenAPI document.
Verifying the signature
| Header | Content |
|---|---|
X-RuangIoT-Event |
Event type, e.g. alert.triggered |
X-RuangIoT-Event-Id |
Event ID — the same for every retry and Resend; use it to ignore duplicates |
X-RuangIoT-Delivery |
Delivery ID (new on every Resend) |
X-RuangIoT-Timestamp |
Unix seconds when it was signed |
X-RuangIoT-Signature |
v1= + hex HMAC-SHA256(secret, "<timestamp>.<raw body>") |
Compute the signature over the raw body (the exact bytes received, before parsing), compare in constant time, and reject timestamps older than 5 minutes.
const crypto = require("crypto");
const express = require("express");
const app = express();
const SECRET = process.env.RUANGIOT_WEBHOOK_SECRET; // whsec_…
app.post("/ruangiot", express.raw({ type: "application/json" }), (req, res) => {
const ts = req.get("X-RuangIoT-Timestamp") || "";
const expected = "v1=" + crypto.createHmac("sha256", SECRET).update(ts + "." + req.body).digest("hex");
const given = req.get("X-RuangIoT-Signature") || "";
const fresh = Math.abs(Date.now() / 1000 - Number(ts)) <= 300;
if (!fresh || given.length !== expected.length || !crypto.timingSafeEqual(Buffer.from(given), Buffer.from(expected))) {
return res.status(401).end();
}
const event = JSON.parse(req.body);
// Ignore duplicates by event.id, then handle event.type …
res.status(204).end();
});
app.listen(3000);
import hashlib, hmac, os, time
from flask import Flask, request, abort
app = Flask(__name__)
SECRET = os.environ["RUANGIOT_WEBHOOK_SECRET"].encode() # whsec_…
@app.post("/ruangiot")
def ruangiot():
ts = request.headers.get("X-RuangIoT-Timestamp", "")
body = request.get_data() # raw body
expected = "v1=" + hmac.new(SECRET, ts.encode() + b"." + body, hashlib.sha256).hexdigest()
given = request.headers.get("X-RuangIoT-Signature", "")
if not ts.isdigit() or abs(time.time() - int(ts)) > 300 or not hmac.compare_digest(given, expected):
abort(401)
event = request.get_json()
print(event["type"], event["id"])
return "", 204
Retries & log
- Your receiver must answer 2xx within 6 seconds. Any other answer, a timeout or a failed connection is retried after 10 seconds, 1 minute, 5 minutes and 30 minutes (5 attempts in total).
- Redirects (3xx) are not followed and count as failures.
- After 25 consecutive failed deliveries the webhook is turned off automatically; turn it on again from its detail page.
- The delivery log is kept for 30 days: time (WIB), event, status, HTTP code, duration, reason and the event body. Receiver response bodies are not stored.
- Resend from the log uses the same event ID and a new delivery ID.
Security
- Public
https://addresses only. Rejected: localhost and internal names, private IPs (10.x, 172.16–31.x, 192.168.x), loopback (127.x, ::1), link-local & cloud metadata (169.254.x, fe80::), CGNAT (100.64.x), ULA (fc00::/7), and addresses with a user name or password. - The host name is checked when saved and on every delivery; the delivery uses the IP from that check (DNS-rebinding safe).
- The URL (often containing a receiver token) and the secret are stored encrypted; only the host and the last 4 characters of the secret are shown.
- Rotate the secret if it leaks — the old secret stops working immediately.