Skip to content

Subscribe to changes#

Two ways to hear about changes. A stream sends every change to the entities you care about, as it happens, over one long-lived connection. A webhook calls your endpoint for a few operational events, such as a runway closing. Use a stream to keep a view current; use webhooks to trigger work.

Streams#

Open GET /airports/{airport}/events. The response is a server-sent events stream: plain HTTP, readable with any client, and it passes through proxies that would block a WebSocket.

curl -N -G https://api.surfacelens.app/v1/airports/VTBS/events \
  -H "Authorization: Bearer $SURFACELENS_KEY" \
  -d types=aircraft,vehicle \
  -d bbox=100.7480,13.6880,100.7580,13.6960

The stream starts with one entity.snapshot event per matching entity, then snapshot.complete, then changes as they are admitted. Your application builds its view from the snapshot and applies changes to it; there is no race between an initial list request and the subscription.

id: 7:48213377
event: entity.snapshot
data: {"revision":48213377,"entity":{"id":"aircraft:8851a4","type":"aircraft","label":"HS-THB","position":{"lat":13.69212,"lon":100.75391},"attributes":{"movement":"parked","stand":"stand:C2"}}}

id: 7:48213377
event: snapshot.complete
data: {"revision":48213377,"count":214}

id: 7:48213421
event: entity.updated
data: {"revision":48213421,"entity":"aircraft:8851a4","changed":{"movement":"pushback","ground_speed_kt":2},"observation":"obs_1Mz5Rf8kW3ta","observed_at":"2026-11-23T02:58:44.900Z"}
Event data
entity.snapshot The full entity, during the initial snapshot.
snapshot.complete The number of snapshot events sent.
entity.created The full entity, when it first appears in the filter.
entity.updated The entity ID and the attributes that changed, with new values.
entity.removed The entity ID, when it leaves the filter or the airport.

An entity that moves into the bbox arrives as entity.created; one that moves out arrives as entity.removed.

A client that resumes#

Connections drop. Every event's id is epoch:revision. Keep the last one, reconnect with it in Last-Event-ID, and the stream resumes after that event, with no gap and no duplicates. Ask for snapshot=false on reconnect: you already have the state.

async function follow(onEvent: (type: string, data: any) => void) {
  let lastId: string | undefined;
  let delay = 1000;
  for (;;) {
    try {
      const params = new URLSearchParams({ types: "aircraft,vehicle" });
      if (lastId) params.set("snapshot", "false");
      const res = await fetch(
        `https://api.surfacelens.app/v1/airports/VTBS/events?${params}`,
        {
          headers: {
            Authorization: `Bearer ${process.env.SURFACELENS_KEY}`,
            ...(lastId ? { "Last-Event-ID": lastId } : {}),
          },
        },
      );
      if (!res.ok) throw new Error(`${res.status}`);
      delay = 1000;
      let buffer = "";
      for await (const chunk of res.body!.pipeThrough(new TextDecoderStream())) {
        buffer += chunk;
        let end;
        while ((end = buffer.indexOf("\n\n")) >= 0) {
          const frame = buffer.slice(0, end);
          buffer = buffer.slice(end + 2);
          const id = /^id: (.+)$/m.exec(frame)?.[1];
          const type = /^event: (.+)$/m.exec(frame)?.[1];
          const data = /^data: (.+)$/m.exec(frame)?.[1];
          if (type && data) onEvent(type, JSON.parse(data));
          if (id) lastId = id;
        }
      }
    } catch (error) {
      console.warn("stream interrupted", error);
    }
    await new Promise((r) => setTimeout(r, delay));
    delay = Math.min(delay * 2, 30_000);
  }
}

SurfaceLens sends a comment line (: keep-alive) every 15 seconds. If you have received nothing for 45 seconds, the connection is dead: close it and reconnect.

The same Last-Event-ID works on the on-premise node, which is how a stream survives failover.

Limits#

Each key may hold 20 open streams. A stream that falls more than 10,000 events behind, because the client is reading too slowly, is closed with a final stream.overflow event; reconnect with Last-Event-ID and narrow the filter.

Webhooks#

Webhooks are for events that are rare and should cause something to happen.

Event Sent when
airfield.status_changed A runway, taxiway or stand opens, closes or changes restriction.
feed.health_changed A feed becomes healthy, degraded or silent.
scenario.completed A scenario succeeds or fails.

Register an endpoint:

curl https://api.surfacelens.app/v1/webhooks \
  -H "Authorization: Bearer $SURFACELENS_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://ops-board.example.net/hooks/surfacelens",
    "events": ["airfield.status_changed", "scenario.completed"],
    "airports": ["VTBS"]
  }'

The response includes a secret starting with whsec_. It is shown once.

Verify each delivery#

Every delivery is a POST with a JSON body and a SurfaceLens-Signature header:

SurfaceLens-Signature: t=1763866802,v1=6f1c0e2a8b3d…

v1 is the hex HMAC-SHA256 of t, a full stop, and the raw request body, keyed with your secret. Reject the delivery if the signature does not match or t is more than five minutes old.

import { createHmac, timingSafeEqual } from "node:crypto";

export function verify(rawBody: string, header: string, secret: string): boolean {
  const parts = Object.fromEntries(header.split(",").map((p) => p.split("=", 2)));
  const t = Number(parts.t);
  if (!t || Math.abs(Date.now() / 1000 - t) > 300) return false;
  const expected = createHmac("sha256", secret).update(`${t}.${rawBody}`).digest();
  const given = Buffer.from(parts.v1 ?? "", "hex");
  return given.length === expected.length && timingSafeEqual(given, expected);
}
import hashlib, hmac, time

def verify(raw_body: bytes, header: str, secret: str) -> bool:
    parts = dict(p.split("=", 1) for p in header.split(","))
    t = int(parts.get("t", "0"))
    if abs(time.time() - t) > 300:
        return False
    expected = hmac.new(secret.encode(), f"{t}.".encode() + raw_body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, parts.get("v1", ""))

Respond with any 2xx within 10 seconds. Do the work after responding. Failed deliveries are retried with exponential backoff for 24 hours; after that the webhook is disabled and you are notified. Deliveries can arrive more than once and out of order: deduplicate on the event id, and use created_at to order.

airfield.status_changed
{
  "id": "evt_3c81f0a9d2",
  "type": "airfield.status_changed",
  "airport": "VTBS",
  "created_at": "2026-11-23T03:00:02Z",
  "data": {
    "entity": "runway:02R-20L",
    "previous": { "status": "open" },
    "current": { "status": "closed", "reason": "inspection", "until": "2026-11-23T03:30:00Z" },
    "observation": "obs_9Ar2Te6mH0kc"
  }
}