Skip to content
Developer documentation

Live rider tracking

Open a session, mint a device credential, ingest positions, read the current state, stream updates and read history.

Live rider tracking

Open a session, mint a device credential, ingest positions, read the current state, stream updates and read history.

Tracking is a separate credential family from maps. Your backend holds the tracking key; the device receives a credential that can only write to its own session. The sequence below is the whole lifecycle.

  1. Create the session

    POST /v1/tracking/sessions with a subject_type and your own external_reference. Use the reference as the idempotency key so a retry cannot open a second session.

  2. Mint a device credential

    POST /v1/tracking/sessions/{session_id}/ingest-token returns a credential bound to that session. Send it to the device through your app session.

  3. Ingest positions

    The device POSTs events with client_event_id and client_seq. Replaying an event id after a timeout is safe; the sequence lets the server repair reordering.

  4. Read state and stream

    GET /state is the current snapshot. GET /stream is a resumable SSE feed. Use state for the first paint and stream for updates.

  5. End the session

    POST /v1/tracking/sessions/{session_id}/end. History remains readable afterwards; the session simply stops accepting events.

ts
// 1. Backend opens the session with the tracking key.
const session = await fetch("https://api.bardiyamap.com/v1/tracking/sessions", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${trackingKey}`,
    "Content-Type": "application/json",
    "Idempotency-Key": "order-1042",
  },
  body: JSON.stringify({ subjectType: "vehicle", externalReference: "order-1042" }),
}).then((response) => response.json());

// 2. Backend mints a credential for that session only.
const device = await fetch(
  `https://api.bardiyamap.com/v1/tracking/sessions/${session.id}/ingest-token`,
  { method: "POST", headers: { Authorization: `Bearer ${trackingKey}` } },
).then((response) => response.json());
ts
// 3. Device sends a position using only its session credential.
await fetch(
  `https://api.bardiyamap.com/api/v1/tracking/sessions/${sessionId}/locations`,
  {
    method: "POST",
    headers: {
      Authorization: `Bearer ${device.token}`,
      "X-Tracking-Organization-Id": organizationId,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      latitude: 30.0444,
      longitude: 31.2357,
      accuracy_m: 8,
      recorded_at: new Date().toISOString(),
      client_event_id: crypto.randomUUID(),
      client_seq: nextSequence(),
    }),
  },
);

Reading the state

GET /v1/tracking/sessions/{session_id}/state is the cheapest way to show where a rider is now. Poll it no faster than your UI needs; for a live view, open the stream instead and fall back to state on reconnect.

History is the source of truth

A stream that was disconnected owes you nothing. After a gap, read GET /v1/tracking/sessions/{session_id}/history for the window and reconcile on (subject, recorded_at). History is durable and paginated; limits up to 500 points per page are accepted.

  • Quality gates apply to history (minimum movement and interval, heading change) so a parked vehicle does not store a point per second. Live state is not filtered that way.
  • Never reconstruct a path from the stream alone: it will have holes wherever the connection dropped.
  • Subscriptions notify you when a subject moves, which is the right primitive for a control tower watching fifty vehicles; the per-session stream is for watching one.