Switch to dark mode

Booking Tickets

How to turn offers into tickets: create a booking, add the passenger details, create and finalize an order, and fetch the tickets.

The booking lifecycle

  1. Booking: Holds the offers you selected and the passengers' details. Nothing is reserved with the operator yet. It expires at expiresAt if you don't create an order from it.

  2. Order: The purchase of a booking. Creating an order pre-books the tickets with the train operator. The tickets are reserved, but not issued yet.

  3. Finalized order: Finalizing the order completes the purchase.

  4. Tickets: The tickets are then issued, usually within 15 minutes.

Creating a booking

Create a booking with createBooking from one or more offer ids. This checks that the offers are still available, but doesn't reserve anything yet.

passengers is optional here, and only takes placeholders: type, age or birth date, travel cards, corporate codes and cost center. The types, ages or birth dates, travel cards and corporate codes must match the passengers you got the offer for. YOUTH and SENIOR passengers need a birthDate or an age, which is used to check that they qualify for the fare. Names, contact details and documents are added afterward with updateBooking.

Example: Create a booking

graphql
mutation CreateBooking {
  createBooking(
    offerIds: ["offer_13e1t02013f5a6t1k4r325r6e0"]
    passengers: [
      { type: ADULT }
      { type: YOUTH, age: 22 }
    ]
  ) {
    id
    passengers {
      id
      age
      type
    }
    requirements {
      passportNumber
      dateOfBirth
      nationality
      email
      tel
    }
    selections {
      ... on JourneyOfferSelection {
        offers {
          ...OfferFragment
        }
        journey {
          ... on JourneySelection {
            itinerary {
              ... on Stopover {
                location {
                  name
                }
              }
              ... on SegmentCollection {
                status
                segments {
                  departureAt
                  arrivalAt
                  origin {
                    name
                  }
                  destination {
                    name
                  }
                }
                offers {
                  ...OfferFragment
                }
              }
            }
          }
        }
      }
    }
  }
}

fragment OfferFragment on Offer {
  id
  price {
    amount
    currency
  }
  parts {
    ... on AdmissionPart {
      conditions {
        __typename
        description
      }
      flexibility
      serviceClass
      comfortClass
    }
    ... on ReservationPart {
      conditions {
        __typename
        description
      }
      flexibility
      comfortClass
      accommodation {
        type
      }
    }
  }
}

The booking's requirements say which passenger details are needed. They differ between train operators. Some need passport numbers, others only names and dates of birth.

Updating passenger details

Before you create an order, add the details listed in the booking's requirements with updateBooking.

Exactly one passenger must be the contact person, with both email and tel. On a booking split across cost centers, each cost center needs its own contact person. The contact person's details are sent to the train operator, who contacts them if there is a problem.

Travel cards and corporate codes can't be changed

A booking is priced on its passengers' travel cards and corporate codes, so leave travelCards and corporateCodes out when updating passengers. To book with a different card or code, create a new booking from a new offer. See Travel Cards and Corporate Codes.

Example: Updating passenger details

graphql
mutation UpdatePassengers {
  updateBooking(
    id: "booking_s5g187p1v0k0p0t5y3x1j79636"
    passengers: [
      {
        id: "8a28690e-e074-4091-b1c4-777042b23de4"
        email: "jane.doe@example.com"
        tel: "+46701234567"
        isContactPerson: true
        birthDate: "1980-02-15"
        nationality: "NL"
        firstName: "Jane"
        lastName: "Doe"
      }
    ]
  ) {
    id
    passengers {
      ... on FullPassenger {
        id
        isContactPerson
        email
        tel
        birthDate
        nationality
        firstName
        lastName
        title
      }
    }
  }
}

Selecting offers

The offerIds you pass to createBooking are the booking's first selection. Each leg of the journey may have other offers, with another fare type or class. To switch to one of them, update the booking with updateBooking:

Example: Select specific offers

graphql
mutation SelectOffer {
  updateBooking(
    id: "booking_s5g187p1v0k0p0t5y3x1j79636"
    selections: [{ offer: { id: "offer_h5w4t5n0t6r3110092f2k15343" } }]
  ) {
    selections {
      ... on JourneyOfferSelection {
        offers {
          id
          price {
            amount
            currency
          }
          parts {
            ... on AdmissionPart {
              flexibility
              serviceClass
              comfortClass
            }
            ... on ReservationPart {
              flexibility
              comfortClass
              accommodation {
                type
              }
            }
          }
        }
      }
    }
  }
}

Offer sets

Some offers can't be selected on their own. They belong to a set that covers several legs of a journey. A leg is a segment collection: a series of segments that are ticketed together.

The rule is the same for every set: select an offer from the set on every leg it covers, or on none of them.

What a set looks like

There are two kinds of set:

  • A fixed combination, with one offer per leg. A return ticket is priced as a whole, so it comes as a full-price offer in one direction and a companion offer at no extra cost in the other. You select exactly those two offers.
  • A journey that is only sold whole. Every offer on every leg belongs to the same set. You can pick any offer you like on each leg, as long as you pick one on every leg.

An offer in a set has memberOf with the id of the set. On other offers memberOf is null, and they can be combined freely. The field also tells you that an offer at no cost is not a free ticket. It is part of a set, and the fare is charged on another leg.

Read memberOf together with the offers from journeyOffer, so you can group them before anything is selected:

graphql
itinerary {
  ... on SegmentCollection {
    offers {
      id
      price {
        amount
        currency
      }
      memberOf {
        id
      }
    }
  }
}

A set id is only for grouping the offers from one search. You always select with an offer's own id, and never send a set id back. Don't store set ids or compare them between searches: a new search returns new offers with new set ids. Two sets with the same price are still two sets, with different ids.

Selecting from a set

Select the offers for every leg of a set in one call: in one offerIds list when you create a booking, or one selections list when you update it. Selecting one leg at a time fails, because the set is incomplete after each call.

On some legs, every offer belongs to a set. Such a leg can only be booked as part of a set, and it can't be left out of the booking either.

A whole round trip can work like that. Some routes are only sold as a return, so every offer in both directions belongs to a set. Each set is a pair: an offer and its companion in the other direction. Pick one pair and select both offers in one call. You can't buy one direction on its own.

Selecting only part of a set fails with OFFER_SET_INCOMPLETE or OFFER_SET_CONFLICT. If the rest of a set is no longer available, creating a booking fails with OFFER_SET_UNAVAILABLE.

Selecting seat preferences

Some offers have place properties: choices such as a window or aisle seat, an upper or lower berth on a night train, or a women-only or other special compartment. Meals and other extras are not place properties. See Adding extras.

A place property with required: true must have an option selected. The others are optional. Set them with updatePart.

Example: Select seat preferences

query GetBooking {
  node(id: "booking_s5g187p1v0k0p0t5y3x1j79636") {
    ... on Booking {
      selections {
        ... on JourneyOfferSelection {
          offers {
            parts {
              ... on ReservationPart {
                id
                placeProperties {
                  id
                  type
                  required
                  availableOptions {
                    id
                    value
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
mutation UpdatePart {
  updatePart(
    id: "6c2dd4ff-2e82-46c9-ba3a-a976bfafccd2"
    booking: "booking_s5g187p1v0k0p0t5y3x1j79636"
    placeProperties: [{
      propertyId: "2f011e64-0cec-48ee-bb1e-b90ec470df0e",
      optionId: "292cf77d-1bd4-4031-b55c-283e6a80282b"
    }]
  ) {
    selections {
      ... on JourneyOfferSelection {
        offers {
          parts {
            ... on ReservationPart {
              id
              placeProperties {
                selectedOption {
                  id
                  value
                }
              }
            }
          }
        }
      }
    }
  }
}

Choosing seats on a seat map

For some trains the passenger can pick an exact seat. Ask for the seat map of a reservation part with placeMapForPart, giving the offer's id and the part's id. It returns null when there is no map for the part, and there is then no seat to choose.

A SeatMap lists the coaches of the train. Each coach has a floorPlan image and its seats, positioned on that image by xpos, ypos, width and height in the image's pixels. Only seats whose availability is AVAILABLE can be chosen.

Record the choice with the placeSelections argument of updatePart, one entry for each passenger you are seating. The seats each passenger holds are in the part's placeAssignments.

Example: Choose a seat

query GetSeatMap {
  placeMapForPart(
    offerId: "offer_13e1t02013f5a6t1k4r325r6e0"
    partId: "6c2dd4ff-2e82-46c9-ba3a-a976bfafccd2"
  ) {
    ... on SeatMap {
      coaches {
        identifier
        floorPlan {
          width
          height
          image {
            url
          }
        }
        seats {
          identifier
          availability
          xpos
          ypos
          width
          height
        }
      }
    }
  }
}
mutation SelectSeat {
  updatePart(
    id: "6c2dd4ff-2e82-46c9-ba3a-a976bfafccd2"
    booking: "booking_s5g187p1v0k0p0t5y3x1j79636"
    placeSelections: [
      {
        seat: {
          passengerId: "pax_4gk5wsa62e9cwa3wbbgs1sayh5"
          coachIdentifier: "7"
          seatIdentifier: "42"
        }
      }
    ]
  ) {
    selections {
      ... on JourneyOfferSelection {
        offers {
          parts {
            ... on ReservationPart {
              id
              placeAssignments {
                ... on SeatAssignment {
                  coachIdentifier
                  seatIdentifier
                  passenger {
                    id
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

Optional seat reservations

On some trains a seat reservation is a choice. Such a reservation part has optional: true, and its included field says whether it is part of the booking, and so of the price, right now. Add it or take it out with the include argument of updatePart:

graphql
mutation IncludeReservation {
  updatePart(
    id: "6c2dd4ff-2e82-46c9-ba3a-a976bfafccd2"
    booking: "booking_s5g187p1v0k0p0t5y3x1j79636"
    include: true
  ) {
    id
  }
}

Toggling a part that isn't optional fails with NOT_OPTIONAL.

Adding extras

A reservation part can offer ancillaries: extras such as a meal, breakfast on a night train or a bicycle space, each with a name, a type and a price. They are bought for one passenger at a time. Add one with the addAncillaries argument of updatePart, naming the ancillary and the passenger it is for.

An ancillary's selections list who has it. To take one off again, pass the id of that selection, not of the ancillary, in removeAncillaries.

Example: Add breakfast for a passenger

graphql
mutation AddAncillary {
  updatePart(
    id: "6c2dd4ff-2e82-46c9-ba3a-a976bfafccd2"
    booking: "booking_s5g187p1v0k0p0t5y3x1j79636"
    addAncillaries: [
      {
        ancillaryId: "0b7d3c1e-5a52-4f0e-9d0b-2f6a1c8e4b77"
        passengerId: "pax_4gk5wsa62e9cwa3wbbgs1sayh5"
      }
    ]
  ) {
    selections {
      ... on JourneyOfferSelection {
        offers {
          parts {
            ... on ReservationPart {
              ancillaries {
                id
                name
                type
                price {
                  amount
                  currency
                }
                selections {
                  id
                  passengerId
                }
              }
            }
          }
        }
      }
    }
  }
}

A passengerId that isn't on the booking fails with INVALID_ANCILLARY_PASSENGER, and one that isn't traveling on that offer with INVALID_ANCILLARY_PASSENGER_FOR_OFFER.

Choosing how tickets are delivered

Some offers can be issued in more than one way: as an e-ticket, or as a "Ticket on Departure" reference that the passenger uses to collect the tickets from a machine at the departure station. Such an offer has a ticketDelivery field:

  • availableOptions lists the ways the offer's tickets can be issued. It always has at least one option. If it has only one, there is nothing for the passenger to choose, so show it as information and not as a picker.
  • selectedOption is the method that will be used. A booking starts with a default, which stays until you set another method. On a search result it is null.

If ticketDelivery is null, the operator decides how the tickets are delivered and there is nothing to set. The one exception is the companion offer of a return fare from a combined journey offer. It has no ticketDelivery of its own, because the delivery of the full-price offer covers both directions. Set the method on the full-price offer instead, which has the same memberOf.id as the companion (see Offer Sets).

Set the method with setTicketDelivery. It takes the offer id and one of the methods in that offer's availableOptions, and returns the updated offer:

Example: Read the options and set the method

query GetBooking {
  node(id: "booking_s5g187p1v0k0p0t5y3x1j79636") {
    ... on Booking {
      selections {
        ... on JourneyOfferSelection {
          offers {
            id
            memberOf {
              id
            }
            ticketDelivery {
              availableOptions {
                method
              }
              selectedOption {
                method
              }
            }
          }
        }
      }
    }
  }
}
mutation SetTicketDelivery {
  setTicketDelivery(
    offerId: "offer_d6b043y5y70665m7s3q0e4h593"
    method: TICKET_ON_DEPARTURE
  ) {
    id
    ticketDelivery {
      selectedOption {
        method
      }
    }
  }
}

Nothing else in the booking changes, so you don't have to fetch it again.

Two single tickets are two offers, and you set the method on each. If the operator delivers them together, they must have the same method. Otherwise creating the order fails with TICKET_DELIVERY_CONFLICT.

setTicketDelivery fails with UNAVAILABLE_TICKET_DELIVERY_METHOD if the method isn't in the offer's availableOptions, or if the offer is the companion of a return fare. An offer id that matches no offer fails with OFFER_NOT_FOUND.

With TICKET_ON_DEPARTURE, the collection reference comes with the finalized order. See Ticket Collection References.

Using the Offer Selection embed

If you don't want to build this interface yourself, use the Offer Selection embed. It lets the user pick an offer, place properties and ancillaries, and updates the booking for them.

html
<aa-offer-selection
  publicApiKey="your-api-key-here"
  booking="booking_s5g187p1v0k0p0t5y3x1j79636"
  offer="offer_23w6h691b4d4x244p185w1x1s6"></aa-offer-selection>

Creating and finalizing orders

When the booking has its passenger details and offers, create an order with createOrder. This pre-books the tickets with the train operator. The step is the same for every payment method:

graphql
mutation CreateOrder {
  createOrder(booking: "booking_s5g187p1v0k0p0t5y3x1j79636") {
    id
    status
    reference
  }
}

Creating an order can take up to 30 seconds, so send it over a WebSocket to avoid timeouts. Offers that the operator delivers together must have the same ticket delivery method. See Choosing How Tickets Are Delivered.

How you complete the order depends on the payment method.

Payment methods

There are three ways to pay for an order: wallet credits, which most API integrations use, the payment gateway for collecting payment from end customers, and invoice. Payment Methods describes each one.

Finalizing with wallet or invoice

With wallet credits or invoice billing, finalize the order yourself with finalizeOrder. This completes the purchase right away, and the tickets are then issued.

Example: Finalize order (wallet/invoice)

graphql
mutation FinalizeOrder {
  finalizeOrder(order: "order_z7s157a0t574a166h3y5n1f5x6") {
    id
    status
    reference
  }
}

Paying with the payment gateway

If your customer pays, pass the order's id to createPayment as orderId instead of finalizing the order yourself. Put the same id in your successUrl, so that the page the customer returns to can look up the order:

Example: Create payment (gateway)

graphql
mutation CreatePayment {
  createPayment(
    orderId: "order_abc123"
    successUrl: "https://example.com/success/order_abc123"
    cancelUrl: "https://example.com/cancel"
  ) {
    url
  }
}

Redirect the customer to the returned url. They pay on All Aboard's hosted page. The order is then finalized automatically, and the customer is sent to your successUrl.

See Payments for the whole payment gateway flow.

Retrieving tickets

Tickets are issued once the order is finalized. Most are ready within 15 minutes, but some take longer, because the train operators need time to produce them. Poll the order with node every few minutes until its resources appear.

The format of a ticket depends on the operator:

PDF tickets

Most tickets are PDF files. The passenger shows the PDF on their phone or prints it.

Some operators require online check-in before departure. The passenger opens the check-in URL, checks in and gets their ticket there.

Ticket collection references

Some UK operators issue a "Ticket on Departure" reference. The passenger enters it at a ticket machine in the station to collect paper tickets.

Other resources

A SelfServiceResource is a link to the operator's own website, where the passenger can manage the booking. Its metadata has details such as the booking number. A FileResource is any other file the operator issued with the booking.

Example: Get tickets from finalized order

graphql
query GetTickets {
  node(id: "order_n4c606w4a281s2m1z240q69494") {
    ... on Order {
      items {
        ... on JourneyOrderItem {
          resources {
            ... on PdfTicket {
              url
            }
            ... on CheckInResource {
              url
            }
            ... on TicketOnDeparture {
              reference
              description
            }
            ... on SelfServiceResource {
              url
              metadata
            }
            ... on FileResource {
              name
              type
              url
            }
          }
        }
      }
    }
  }
}

The full flow

This page covers creating and completing a booking. For the whole flow from search to tickets, including payment, see Booking Flows.