Webhooks
Instead of asking whether a takeoff is done, give InsulEngine a URL and it calls you the moment it is. Each call is signed so you can tell it came from InsulEngine.
Add a webhook
A company admin opens Settings → API & webhooks, enters an HTTPS URL on the public
internet, picks the events and presses Add webhook. The page shows the endpoint's
signing secret (whsec_…) once: store it with your API key. Send a test
posts a webhook.test event at once, so you can check your receiver before a real job.
Events
| Event | Sent when |
|---|---|
takeoff.completed | A takeoff is done and shown in the app. Once per takeoff run. |
estimate.priced | The takeoff that was just completed has been priced. Sent right after its
takeoff.completed, once per estimate. |
webhook.test | You pressed Send a test. Its data is empty. |
InsulEngine checks every takeoff before it is shown. A takeoff our checks hold back is not announced until it has been reviewed and shown (see How it works). Changes made by hand in the app, such as a price edited on the estimate page, are not announced: read the estimate when you need it. When an endpoint is set up with no events picked, it gets them all, including any added later.
What arrives
POST /your/endpoint
Content-Type: application/json
User-Agent: InsulEngine-Webhooks/1
X-InsulEngine-Event: takeoff.completed
X-InsulEngine-Delivery: takeoff.completed:ae8c4158-…
X-InsulEngine-Signature: t=1763733600,v1=5f2b9c…
{"id": "takeoff.completed:ae8c4158-…",
"type": "takeoff.completed",
"created": 1763733600,
"data": {"job_id": "c74f3ef7-…", "job_name": "Hope 4 Youth",
"takeoff_version": 1, "run_id": "ae8c4158-…",
"estimate": {"id": "5e6f7321-…", "version": 3, "sell_price": 11073.32},
"links": {"job": "/v1/jobs/c74f3ef7-…",
"takeoff": "/v1/jobs/c74f3ef7-…/takeoff",
"estimate": "/v1/jobs/c74f3ef7-…/estimate"}}}
Answer with any 2xx within 10 seconds, then do the work (read the takeoff, update your system)
afterwards. The body is small on purpose: fetch what you need from links with your API key.
Verify the signature
X-InsulEngine-Signature carries a timestamp t and v1, the hex
HMAC-SHA256 of t, a period, and the raw request body, keyed with your endpoint's signing secret.
Compute it over the raw bytes you received (not re-serialized JSON), compare in constant time, and
refuse a timestamp more than five minutes old so a captured call cannot be replayed.
Python
import hashlib
import hmac
import time
def verify(secret: str, body: bytes, header: str, tolerance: int = 300) -> bool:
"""True when a webhook's X-InsulEngine-Signature matches its raw body."""
try:
parts = dict(part.split("=", 1) for part in header.split(","))
timestamp, signature = parts["t"], parts["v1"]
except (KeyError, ValueError):
return False
expected = hmac.new(secret.encode(), timestamp.encode() + b"." + body, hashlib.sha256).hexdigest()
fresh = abs(time.time() - int(timestamp)) <= tolerance
return fresh and hmac.compare_digest(expected, signature)
Node.js
const crypto = require("crypto");
// True when a webhook's X-InsulEngine-Signature matches its raw body (a Buffer).
function verify(secret, body, header, tolerance = 300) {
const parts = Object.fromEntries(header.split(",").map(p => p.split(/=(.*)/s).slice(0, 2)));
if (!parts.t || !parts.v1) return false;
const expected = crypto.createHmac("sha256", secret)
.update(Buffer.concat([Buffer.from(parts.t + "."), body])).digest("hex");
const fresh = Math.abs(Date.now() / 1000 - Number(parts.t)) <= tolerance;
return fresh && expected.length === parts.v1.length &&
crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1));
}
module.exports = { verify };
A receiver
Verify against the raw body, answer at once, and do the work after answering.
import os
from flask import Flask, abort, request
app = Flask(__name__)
SECRET = os.environ["INSULENGINE_WEBHOOK_SECRET"]
seen = set()
@app.post("/insulengine")
def insulengine():
if not verify(SECRET, request.get_data(), request.headers.get("X-InsulEngine-Signature", "")):
abort(400)
event = request.get_json()
if event["id"] in seen: # a retry of one already handled
return "", 204
seen.add(event["id"])
if event["type"] == "takeoff.completed":
queue_import(event["data"]["job_id"]) # read the takeoff after answering
return "", 204
const express = require("express");
const { verify } = require("./verify");
const app = express();
const SECRET = process.env.INSULENGINE_WEBHOOK_SECRET;
const seen = new Set();
// express.raw keeps the body as the bytes that were signed.
app.post("/insulengine", express.raw({ type: "application/json" }), (req, res) => {
if (!verify(SECRET, req.body, req.get("X-InsulEngine-Signature") || "")) return res.sendStatus(400);
const event = JSON.parse(req.body);
if (seen.has(event.id)) return res.sendStatus(204); // a retry of one already handled
seen.add(event.id);
res.sendStatus(204); // answer first, then do the work
if (event.type === "takeoff.completed") queueImport(event.data.job_id);
});
app.listen(3000);
Keep the ids you have handled somewhere that lasts, such as your database, rather than in memory as these examples do.
Retries
A call that does not answer 2xx in 10 seconds (an error, a timeout, a redirect) is tried again
after 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours and 24 hours, then given up. A retry carries the same
X-InsulEngine-Delivery and body id; because a call that timed out may still have reached
you, use the id to ignore one you have already handled. Redirects are not followed: give the final URL.
The settings page lists each endpoint's last 50 deliveries with their result, and Resend sends one again.
Testing
- Send a test on the settings page posts a
webhook.testevent at once and shows what your server answered. - The URL must be HTTPS on the public internet. To receive on your own computer while you build, use a tunnel that gives you a public HTTPS address, such as Cloudflare Tunnel or ngrok, and remove that endpoint when you are done.
- Make a job from a small drawing set to see a real
takeoff.completedandestimate.pricedarrive.