Code recipes
Drop these into your codebase. Replace the placeholders with your own site key and webhook secret (kept in your secret manager — never client-side).
Send any event (universal helper)
One function you can reuse for every event type. Computes the HMAC, sends the request, returns the response.
import { createHmac } from "crypto";
const SITE_KEY = process.env.ENVARA_SITE_KEY;const SECRET = process.env.ENVARA_WEBHOOK_SECRET;
export async function sendEnvaraEvent(source, event, payload) { const body = JSON.stringify(payload); const ts = Math.floor(Date.now() / 1000); const sig = createHmac("sha256", SECRET).update(body).digest("hex");
const res = await fetch(`https://bridge.envara.ae/api/public/ingest/${source}/${event}`, { method: "POST", headers: { "Content-Type": "application/json", "X-Envara-Site-Key": SITE_KEY, "X-Envara-Signature": `sha256=${sig}`, "X-Envara-Timestamp": String(ts), }, body, }); return res.json();}Example: order created
await sendEnvaraEvent("generic", "order.created", { event: "order.created", order: { id: "12345", number: "1042", total: "199.00", currency: "AED", items_count: 2, customer: { first_name: "Ada", phone_e164: "+9715XXXXXXXX", }, order_url_customer: "https://acme.com/order/1042", },});Example: user OTP / verification
await sendEnvaraEvent("generic", "user.verification", { event: "user.verification", customer: { first_name: "Ada", phone_e164: "+9715XXXXXXXX", }, data: { code: "938472", expires_in: "5 minutes", },});Example: appointment reminder
send_envara_event("generic", "appointment.reminder", { "event": "appointment.reminder", "customer": { "first_name": "Ada", "phone_e164": "+9715XXXXXXXX", }, "data": { "starts_at": "Tomorrow, 3:00 PM", "location": "Clinic, Dubai Marina", },})Example: abandoned cart
sendEnvaraEvent('generic', 'cart.abandoned', [ 'event' => 'cart.abandoned', 'cart' => [ 'id' => 'cart_abc', 'total' => '149.00', 'currency' => 'AED', 'items_count' => 3, 'recovery_url' => 'https://acme.com/cart/restore/abc', ], 'customer' => [ 'first_name' => 'Ada', 'phone_e164' => '+9715XXXXXXXX', ],]);