Switch to dark mode

Getting Offers

Once you have a journey, the next step is to get its offers: the ways to travel it, each with a price, a fare type and a class.

What is an offer?

An offer is a priced way to travel a journey, or one leg of it. Each offer has:

  • A price: The total for your passengers.
  • A fare type: How flexible the ticket is, meaning whether it can be changed or refunded.
  • A service class: The level of comfort, such as standard or first class.
  • Reservations: Whether seat reservations are included or required.

A journey usually has several offers to choose from, for example:

  • A cheap, non-refundable one
  • A flexible, refundable one, usually at a higher price
  • A first-class one with reserved seats

Getting offers for a journey

Use the journeyOffer query, or the subscription, to get the offers for a journey. You need:

  • The journey id from your search results
  • The passengers: how many are traveling, and their types

Train operators limit how many passengers one booking can have. If your party is too large for the operator of a leg, that leg's SegmentCollection has the status TOO_MANY_PASSENGERS and no offers. Everyone counts toward the limit, including children and infants.

Use the subscription

Getting offers can take up to 30 seconds, because the train operators' systems are slow. With the subscription, offers arrive leg by leg and you can show them as they come in. See Subscriptions and Streaming.

Example: Get offers for a journey

graphql
subscription JourneyOffer {
  journeyOffer(
    journeyId: "a1f5aad4-e126-4d08-ad7c-47cfa867fdec"
    passengers: [{ type: ADULT }]
  ) {
    status
    itinerary {
      __typename
      ... on SegmentCollection {
        status
        segments {
          departureAt
          origin {
            name
            ... on Location {
              countryCode
            }
          }
          distance {
            value
            unit
          }
          co2 {
            value
            unit
          }
        }
        offers {
          id
          price {
            amount
            currency
          }
          parts {
            ... on AdmissionPart {
              conditions {
                __typename
                description
                ... on ReturnCondition {
                  type
                  timeframe
                }
                ... on ValidityCondition {
                  validFrom
                  validUntil
                  breakOfJourney
                }
                ... on TravelCondition {
                  type
                  url
                }
              }
              flexibility
              serviceClass
              comfortClass
            }
            ... on ReservationPart {
              conditions {
                __typename
                description
                ... on ReturnCondition {
                  type
                  timeframe
                }
              }
              flexibility
              comfortClass
              accommodation {
                type
              }
            }
          }
        }
      }
      ... on Stopover {
        location {
          name
          countryCode
        }
      }
    }
  }
}

Each segment's distance and co2 are for one passenger. See Distance and CO2e for how they are calculated.

Pricing journeys counts toward your sales agent's offer limit. When the limit is used up, a leg has the status RATE_LIMITED and no offers, until the limit resets. See the rateLimits field of SalesAgent for your limit and when it resets.

Round trips

Some operators sell a return ticket that is cheaper than two singles. They only quote it when they are asked for both directions at once, so a round trip has to be priced in one call.

Use combinedJourneyOffer, or its subscription, for this. It takes one journey id per direction, from two ordinary journeys searches in opposite directions, and the passengers who travel both ways:

Example: Price an outbound and an inbound journey together

graphql
subscription CombinedJourneyOffer {
  combinedJourneyOffer(
    outboundJourneyId: "5fe30aba-cb4a-4d56-afd9-5932f6898f47"
    inboundJourneyId: "3a3bec07-2439-4de4-ab0a-31a1605f26de"
    passengers: [{ type: ADULT }]
  ) {
    outbound {
      status
      itinerary {
        ... on SegmentCollection {
          status
          offers {
            id
            price {
              amount
              currency
            }
            memberOf {
              id
            }
          }
        }
      }
    }
    inbound {
      status
      itinerary {
        ... on SegmentCollection {
          status
          offers {
            id
            price {
              amount
              currency
            }
            memberOf {
              id
            }
          }
        }
      }
    }
  }
}

The result has an outbound and an inbound journey offer. Each one is what journeyOffer would have returned for that direction, so the code you have for a one-way offer works for both.

The difference is in the prices. Where the return follows the same route as the outbound, and the operator sells a return fare for it, that fare replaces the two one-way prices. Where the two directions take different routes, or the operator has no return fare, you get the same prices as from two separate journeyOffer calls. The call works the same way in both cases, so you don't need a fallback.

A return fare comes as two offers: a full-price offer in one direction, and a companion offer at no cost in the other. Together they are one ticket, and they can only be booked together. Offers with the same memberOf.id belong to the same set. Select an offer from the set in both directions, or in neither. See Offer Sets.

Book a round trip as one booking. Pass the offer ids you selected from both directions to createBooking in one offerIds list. A return fare can't be split across two bookings.

Pricing two directions takes at least as long as pricing one, so use the subscription here too. Each direction streams independently, and you get an update whenever either of them has something new.

Offer parts

An offer is made up of parts that describe what is included. There are two main kinds:

Admission parts

An admission is the right to travel: the ticket itself. It has:

  • Flexibility: Whether the ticket can be changed or refunded (FULL_FLEX, SEMI_FLEX, NON_FLEX, or UNKNOWN when the operator doesn't say).
  • Service class: The level of comfort, on one scale for every operator (BEST, HIGH, STANDARD, BASIC).
  • Comfort class: First class, second class and so on.

Reservation parts

A reservation is a reserved seat or berth. It has:

  • Flexibility: As for admission parts.
  • Comfort class: The class of the reserved place.
  • Accommodation: The kind of place, such as a seat, a couchette or a sleeper.

Most offers have both an admission and a reservation. Some trains only require an admission, and the passenger sits anywhere in their class.

Ticket conditions

Both kinds of part have conditions: the rules the operator has stated for the ticket. Each condition has a description, which is complete text that you can show to the traveler as it is, and a __typename that says what kind of rule it is:

  • ReturnCondition: A refund or exchange rule. type says which of the two, or UNKNOWN if the operator didn't say. timeframe says when the ticket can be refunded or exchanged: ALWAYS, BEFORE_DEPARTURE, NEVER or UNKNOWN.
  • ValidityCondition: The dates the ticket can be used on. validFrom and validUntil are dates without a time of day, in the operator's local time zone, and both days are included. breakOfJourney says whether the passenger may stop on the way and continue later. It is null if the operator didn't say.
  • TravelCondition: Another rule for using the ticket. type is ROUTE (the ticket is tied to particular services or a particular route), TRAIN_BOUND (only valid on the booked train) or RESTRICTION (limits on the times of day it can be used). url links to the full wording, when there is one.

description is on every Condition. Select the other fields with an inline fragment for each kind:

graphql
conditions {
  __typename
  description
  ... on ReturnCondition {
    type
    timeframe
  }
  ... on ValidityCondition {
    validFrom
    validUntil
    breakOfJourney
  }
  ... on TravelCondition {
    type
    url
  }
}

The list only has what the operator stated. If a kind is missing, the operator didn't say, which is not the same as there being no rule. A ticket without a ValidityCondition isn't valid indefinitely. Its validity dates are unknown.

New kinds may appear

More kinds of condition may be added over time. For a __typename you don't recognize, show the description instead of dropping the condition.

Passenger requirements

Every passenger has a type, which is an age band: YOUTH is 0 to 27 and includes children, ADULT is 28 to 59, and SENIOR is 60 and over. What else you send depends on the passenger:

  • Adults: Age or birth date is optional.
  • Youths and seniors: Age or birth date is required, because the discount depends on it.
  • Card holders: Attach discount cards and rail passes with travelCards. See Travel Cards.
  • Corporate travelers: Attach negotiated-rate agreements with corporateCodes. See Corporate Codes.

Offer availability

A journey in the search results doesn't always have offers. journeyOffer checks live availability with the train operators, and a leg can come back without offers because:

  • Tickets aren't on sale yet.
  • Tickets are sold out.
  • That exact journey can't be booked, although a similar one might be.

When there are offers, their departure times can differ slightly from the journey you searched for. The route, the comfort level and safe connection times between trains are kept.

Choosing which journey to price

A search returns several journeys for the same day. Only request offers for the ones your users are likely to book (see API Usage and Look-to-Book). There are three ways to choose:

Filter by journey type

If you know which type of journey your users want, SMART, NON_STOP or BLUEPRINT, filter the search on it. See Filter by Journey Type.

Use journey ratings

getJourneyRatings scores journeys on travel time, comfort, connection quality and more. A rating is between 0 and 1, where 1 is the best. Ratings are relative. Each journey is scored against the others in the same call, so a rating can't be compared with ratings from another call. Use it to compare journeys and price the best one:

Example: Compare journey ratings

graphql
query GetJourneyRatings {
  getJourneyRatings(
    journeys: [
      "8280f7b5-40dc-451f-8fde-530909045dc3"
      "0a947ce4-c1d9-4aab-a786-2404fb2d8d1b"
      "d0fef2d5-d1d1-4013-bc07-1f79ea1e320b"
    ]
  )
}

Let users choose

In a user-facing application, list the journeys with their departure and arrival times, number of changes and total travel time. Then price the journey the user selects.

Next steps

Booking Tickets
Create a booking from an offer, add passengers, select offers and seats, and complete the purchase.