Switch to dark mode

API Basics

The All Aboard API is a GraphQL API with a live and a test environment. To use it you need:

API endpoints

  • Live: https://api-gateway.allaboard.eu
  • Test: https://test.api-gateway.allaboard.eu

The API takes HTTP POST requests and WebSocket connections. Use a WebSocket for slow operations and for streamed results. A GET request with the operation in a query parameter also works, but it can't carry variables, so use POST.

Open either URL in a browser for a GraphQL console, where you can browse the schema and run queries: live or test.

Required headers

Send these headers with every request:

Header Description
api-key Your API key from the Dashboard
session A unique identifier for the user session (see below)
Accept application/graphql-response+json (HTTP only)
Content-Type application/json (HTTP POST only)

A POST without Content-Type: application/json is not read as JSON and fails with a 500, before any GraphQL runs. See Transport errors.

Authentication

Each API key has a set of scopes. They decide which environment the key can use and what it can do there. A request fails if the key lacks a scope the operation needs. See API Scopes for the full list.

Keep your API key on your server. A public page that shows or refunds an order should use an access token for that order instead. The token goes in the api-key header, in place of the key.

Session header

The session header identifies one user's session. Use any unique string, such as a UUID. Generate one per user session and send it with every request in that booking flow. We use it to trace requests when something goes wrong.

HTTP example

http
POST / HTTP/1.1
Host: api-gateway.allaboard.eu
Accept: application/graphql-response+json
api-key: your-api-key-here
session: 550e8400-e29b-41d4-a716-446655440000
Content-Type: application/json

{"query": "..."}

WebSocket example

A WebSocket connection often can't set custom headers, for example in a browser. Send the same values as connection parameters instead (see the graphql-ws documentation):

javascript
connectionParams: {
  'api-key': 'your-api-key-here',
  'session': '550e8400-e29b-41d4-a716-446655440000'
}

WebSockets and streaming

Some operations take up to 30 seconds, because the train operators' own systems are slow. Use a WebSocket for these:

  • Getting offers: a subscription streams the prices as they arrive.
  • Creating bookings and orders: a WebSocket avoids request timeouts.

See Subscriptions and Streaming.

Client libraries

Most languages have a GraphQL client. Find one for yours on the official GraphQL website.

For WebSocket connections, use the graphql-ws library in JavaScript, or a library in your language that speaks the same protocol. Check two things when you choose one:

  • Subprotocol: The connection must be opened with the graphql-transport-ws subprotocol, which is what the graphql-ws library uses. The older subprotocol that is itself named graphql-ws, from the retired subscriptions-transport-ws library, is refused with a 426.
  • Keepalive: The API sends a ping message every 12 seconds, and closes the connection with code 4499 if no pong comes back within a few seconds. The graphql-ws library answers pings by itself. With another client, make sure it does.

API usage and look-to-book

The look-to-book ratio is the number of searches you make for each booking. Many travel APIs put a hard limit on it. We don't. We ask for fair use instead:

  • Request offers when a user is looking at a journey they may book.
  • Don't request offers "just in case", or to fill a database of prices.
  • Don't scrape timetables or prices across many routes or dates.

This keeps the API fast for everyone. If you are unsure whether your usage is fair, ask us at tech@allaboard.eu.

Rate limits

Apart from fair use, three things are counted per sales agent: timetable lookups when you find journeys, the prices we fetch from operators when you ask for offers, and the orders you finalize. Once a limit is used up, further requests get RATE_LIMITED until it resets. The limits depend on your agreement with us. Read yours, and how much is left of each, from getSalesAgent:

graphql
query GetRateLimits {
  getSalesAgent {
    rateLimits {
      resource
      unit
      limit
      remaining
      resetAt
    }
  }
}

Each RateLimit covers one resource over one unit of time: timetable per HOUR and per DAY, offer (pricing) per HOUR and order (finalizing) per MINUTE. remaining counts down from limit and is full again at resetAt.

Next steps

Key Concepts
Rail terms like journeys, offers, bookings and orders.
Booking Flows
The complete booking lifecycle, from search to tickets.
Access Tokens
Give a public page one order without exposing your API key.
Subscriptions and Streaming
WebSockets for real-time updates, without timeouts.
Finding Journeys
Search for train routes between two places.
Getting Offers
Prices and fare options for a journey.

API reference material

API Types
Every query, mutation and type in the GraphQL schema.
Error Codes
What each error code means and how to handle it.