Skip to content

Connect a feed#

Connect an AODB flight schedule to the shared model. You will register the feed, write a mapping for its records, test the mapping against real samples, activate the feed and push records. Every application with access to VTBS then sees the flights, without its own adapter.

You need a test key whose application has feeds:write, feeds:read and records:write. Test keys write to a private copy of the sandbox, discarded after 24 hours, so you can run this guide as often as you like.

The source record#

The AODB sends one JSON message per change to a flight. This is the one we will map:

AODB message
{
  "MsgId": "AODB-7781243",
  "FlightId": "TG403-20261123",
  "Airline": "TG",
  "FltNo": "403",
  "Dir": "D",
  "Orig": "VTBS",
  "Dest": "WSSS",
  "STD": "2026-11-23T10:25:00+07:00",
  "ETD": "2026-11-23T10:35:00+07:00",
  "Reg": "HS-THB",
  "Stand": "C2",
  "LastUpdate": "2026-11-23T09:40:12+07:00"
}

It describes a flight (TG403-20261123), its schedule, and two links: the aircraft by registration, and the stand by name. In the shared schema, that is one flight entity with a schedule observation and an allocation observation.

Register the feed#

curl https://api.surfacelens.app/v1/feeds \
  -H "Authorization: Bearer $SURFACELENS_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "airport": "VTBS",
    "name": "AODB flight schedule",
    "kind": "flight_schedule",
    "transport": "push",
    "priority": 50
  }'
const res = await fetch("https://api.surfacelens.app/v1/feeds", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.SURFACELENS_KEY}`,
    "Content-Type": "application/json",
    "Idempotency-Key": crypto.randomUUID(),
  },
  body: JSON.stringify({
    airport: "VTBS",
    name: "AODB flight schedule",
    kind: "flight_schedule",
    transport: "push",
    priority: 50,
  }),
});
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
const feed = await res.json();
import os, uuid, httpx

res = httpx.post(
    "https://api.surfacelens.app/v1/feeds",
    headers={
        "Authorization": f"Bearer {os.environ['SURFACELENS_KEY']}",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
        "airport": "VTBS",
        "name": "AODB flight schedule",
        "kind": "flight_schedule",
        "transport": "push",
        "priority": 50,
    },
)
res.raise_for_status()
feed = res.json()
{
  "id": "feed_8b41e07c35",
  "object": "feed",
  "airport": "VTBS",
  "name": "AODB flight schedule",
  "kind": "flight_schedule",
  "transport": "push",
  "priority": 50,
  "status": "draft",
  "mapping_version": null,
  "created_at": "2026-11-23T02:10:04Z",
  "ingest_url": "https://api.surfacelens.app/v1/feeds/feed_8b41e07c35/records"
}

The feed is draft until it has a mapping and you activate it. priority decides which feed wins when two report the same attribute for the same instant; the AODB is authoritative for schedules but not for positions, so 50 is a reasonable middle.

export FEED=feed_8b41e07c35

Write the mapping#

A mapping says, for one source record: which record it is, when it was true, which entity it describes, and what observations to produce.

mapping.json
{
  "record_id": "$.MsgId",
  "observed_at": { "from": "$.LastUpdate", "as": "timestamp" },
  "entity": { "type": "flight", "key": "$.FlightId" },
  "emit": [
    {
      "kind": "schedule",
      "data": {
        "airline": "$.Airline",
        "number": "$.FltNo",
        "direction": { "from": "$.Dir", "as": { "map": { "A": "arrival", "D": "departure" } } },
        "origin": "$.Orig",
        "destination": "$.Dest",
        "scheduled_at": { "from": "$.STD", "as": "timestamp" },
        "estimated_at": { "from": "$.ETD", "as": "timestamp" }
      }
    },
    {
      "kind": "allocation",
      "data": {
        "aircraft": { "ref": "aircraft", "by": "registration", "from": "$.Reg" },
        "stand": { "ref": "stand", "from": "$.Stand" }
      }
    }
  ]
}

Each value takes one of four forms:

"$.Dest"
A JSONPath into the record. Dot and index access only: $.legs[0].Dest.
{ "const": "TG" }
A literal value.
{ "from": …, "as": … }
A conversion: timestamp (any RFC 3339 offset, converted to UTC), unix_ms, unix_s, number, integer, upper, lower, trim, or { "map": { … } } for a lookup table.
{ "ref": …, "from": … }
A link to another entity. With by, SurfaceLens resolves an attribute to an ID: registration HS-THB becomes aircraft:8851a4.

Attribute names in data must be shared-schema names for the entity type; see entity types.

Test it#

Run sample records through the mapping before you save it. Nothing is stored.

curl https://api.surfacelens.app/v1/feeds/$FEED/mapping/test \
  -H "Authorization: Bearer $SURFACELENS_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"mapping\": $(cat mapping.json), \"records\": [$(cat aodb-message.json)]}"
{
  "object": "mapping_test",
  "mapping_version": null,
  "results": [
    {
      "index": 0,
      "ok": true,
      "entity": "flight:TG403-20261123",
      "observations": [
        {
          "kind": "schedule",
          "observed_at": "2026-11-23T02:40:12Z",
          "data": {
            "airline": "TG",
            "number": "403",
            "direction": "departure",
            "origin": "VTBS",
            "destination": "WSSS",
            "scheduled_at": "2026-11-23T03:25:00Z",
            "estimated_at": "2026-11-23T03:35:00Z"
          }
        },
        {
          "kind": "allocation",
          "observed_at": "2026-11-23T02:40:12Z",
          "data": { "aircraft": "aircraft:8851a4", "stand": "stand:C2" }
        }
      ],
      "errors": []
    }
  ]
}

Check three things: the entity ID is the one you expect, the times are in UTC (10:25 in Bangkok is 03:25Z), and references resolved to IDs. A record that fails says where:

{
  "index": 0,
  "ok": false,
  "observations": [],
  "errors": [
    {
      "code": "unknown_reference",
      "path": "$.Reg",
      "message": "No aircraft with registration \"HS-TBX\" is known at VTBS."
    }
  ]
}

Test with a day's worth of real messages, including cancellations and diversions, before you go further. The endpoint takes 50 records per call.

Save and activate#

Save the mapping. Each save creates a new version; records keep the version they were mapped with.

curl -X PUT https://api.surfacelens.app/v1/feeds/$FEED/mapping \
  -H "Authorization: Bearer $SURFACELENS_KEY" \
  -H "Content-Type: application/json" \
  -d @mapping.json

Then activate the feed:

curl -X PATCH https://api.surfacelens.app/v1/feeds/$FEED \
  -H "Authorization: Bearer $SURFACELENS_KEY" \
  -H "Content-Type: application/json" \
  -d '{"status": "active"}'

Push records#

Send records to the feed's ingest_url, up to 500 per request.

curl https://api.surfacelens.app/v1/feeds/$FEED/records \
  -H "Authorization: Bearer $SURFACELENS_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"records\": [$(cat aodb-message.json)]}"
const res = await fetch(`https://api.surfacelens.app/v1/feeds/${process.env.FEED}/records`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.SURFACELENS_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ records: messages }),
});
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
const { results } = await res.json();
for (const r of results.filter((r) => r.status === "rejected")) {
  console.error(r.record_id, r.errors);
}
import os, httpx

res = httpx.post(
    f"https://api.surfacelens.app/v1/feeds/{os.environ['FEED']}/records",
    headers={"Authorization": f"Bearer {os.environ['SURFACELENS_KEY']}"},
    json={"records": messages},
)
res.raise_for_status()
for r in res.json()["results"]:
    if r["status"] == "rejected":
        print(r["record_id"], r["errors"])
{
  "object": "ingest_result",
  "results": [
    {
      "index": 0,
      "record_id": "AODB-7781243",
      "status": "admitted",
      "observations": ["obs_5Hv1Xb7sM3jk", "obs_8Tq4Bn2xC6wd"],
      "errors": []
    }
  ]
}

Each record succeeds or fails on its own, so the response is 200 even when some records are rejected. Read status on every result. Sending the same batch again returns duplicate for records already admitted, so a timeout is always safe to retry.

Read it back#

The flight is now part of the shared model.

curl https://api.surfacelens.app/v1/airports/VTBS/entities/flight:TG403-20261123 \
  -H "Authorization: Bearer $SURFACELENS_KEY"
{
  "id": "flight:TG403-20261123",
  "object": "entity",
  "type": "flight",
  "label": "TG403",
  "position": null,
  "attributes": {
    "airline": "TG",
    "number": "403",
    "direction": "departure",
    "destination": "WSSS",
    "scheduled_at": "2026-11-23T03:25:00Z",
    "estimated_at": "2026-11-23T03:35:00Z",
    "aircraft": "aircraft:8851a4",
    "stand": "stand:C2"
  },
  "observed_at": "2026-11-23T02:40:12Z",
  "provenance": {
    "scheduled_at": "obs_5Hv1Xb7sM3jk",
    "estimated_at": "obs_5Hv1Xb7sM3jk",
    "stand": "obs_8Tq4Bn2xC6wd"
  }
}

Run it in production#

  • Watch health. Feed health reports throughput, latency and rejections. Subscribe to the feed.health_changed webhook so a silent feed pages someone.
  • Give the adapter its own application with records:write for this feed only. See Applications and scopes.
  • Configure both base URLs if the airport has an on-premise node, so the adapter keeps delivering when the edge is unreachable. See Fail over to on-premise.
  • Change mappings with a test first. Test the new mapping against yesterday's records, then save it. Records already admitted keep their old version.