Rydmate API

Rydmate Node.js API

Connect your Node.js application to Rydmate: read the fleet, hold seats and hear about every change. There is no separate library to install. The API speaks plain HTTPS and JSON, so Node.js's own tools are enough.

Node.js 18 or laterAPI reference

Before you start

  • Create an API key in Rydmate under Developers. A key starting with ryd_test_ works on your test account, so nothing you try touches real trips or money.
  • Set it as RYDMATE_API_KEY in your environment. Never put the key in your code or your app.
  • No packages to install: fetch and crypto are built into Node.js. Save the files with the .mjs extension.
1

List your vehicles

The simplest request: every vehicle in the business, with its registration and status. If something goes wrong, the error says what, and carries a reference our team can look up.

list.mjs
const API = process.env.RYDMATE_API_URL ?? "https://api.rydmate.com/api/v1";

const res = await fetch(`${API}/vehicles`, {
  headers: { Authorization: `Bearer ${process.env.RYDMATE_API_KEY}` },
});
const body = await res.json();
if (!res.ok) {
  const { code, message, request_id } = body.error;
  throw new Error(`${code}: ${message} (${request_id})`);
}

for (const vehicle of body.data) {
  console.log(vehicle.registration_number, vehicle.status);
}

Run it with node list.mjs.

2

Hold a seat without double bookings

Hold a seat on a departure for a passenger. The Idempotency-Key header means that if the connection drops and you send the same request again, you still get one hold, not two.

If another counter took the seat first, Rydmate answers with a conflict instead of booking it twice. Once the passenger has paid, confirm the hold with POST /bookings/{id}/transition and {"to": "CONFIRMED"}.

book.mjs
import { randomUUID } from "node:crypto";

const API = process.env.RYDMATE_API_URL ?? "https://api.rydmate.com/api/v1";

const res = await fetch(`${API}/trips/${process.env.TRIP_ID}/bookings`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.RYDMATE_API_KEY}`,
    "Content-Type": "application/json",
    // Keep this key and send it again on a retry: you get one hold, never two.
    "Idempotency-Key": randomUUID(),
  },
  body: JSON.stringify({
    seat_number: "3A",
    passenger: { full_name: "Ngozi Okafor" },
    channel: "PUBLIC_WEB",
  }),
});
const body = await res.json();

if (res.status === 409) {
  console.log("Seat already taken:", body.error.message);
} else if (!res.ok) {
  throw new Error(`${body.error.code}: ${body.error.message}`);
} else {
  console.log("Seat held", body.data.id);
}
3

Check that an update really came from Rydmate

Rydmate tells your system the moment a trip, ticket, delivery or payment changes. Each update is signed with your endpoint's secret. Check the signature before you act on it, and refuse anything older than five minutes.

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

// Checks the Rydmate-Signature header on a webhook delivery.
// rawBody must be the request body exactly as it arrived.
export function verifyRydmateSignature(secret, header, rawBody, toleranceSeconds = 300) {
  const parts = Object.fromEntries(
    header.split(",").map((part) => part.trim().split("=", 2)),
  );
  const t = Number(parts.t);
  if (!parts.v1 || !Number.isInteger(t)) return false;
  if (Math.abs(Date.now() / 1000 - t) > toleranceSeconds) return false;

  const expected = createHmac("sha256", secret).update(`${parts.t}.`).update(rawBody).digest("hex");
  const a = Buffer.from(expected);
  const b = Buffer.from(parts.v1);
  return a.length === b.length && timingSafeEqual(a, b);
}

Build on Rydmate

Connect your product to real transport operations

Start on a test account, then go live when your integration is ready. Book a demo to talk through what you are building.