Switch to dark mode

Journey Cards Embed

The Journey Cards embed shows journeys that your own code gives it, as the cards the Journey List is made of.

It makes no API requests and needs no API key. You get the journeys from the API wherever you make your own calls, and set them on the element. Use it when you already have the journeys, or when the page can't hold an API key, such as a frame inside a chat app.

If you want the embed to search for journeys and price them itself, use the Journey List.

The cards are responsive and adapt to the user's screen size. Scroll down to see an example.

Getting started

First load the script. It is a standard JavaScript module, so the script tag needs type="module".

html
<script src="https://allaboard.eu/embed/aa-journeys.js" type="module"></script>

The script registers the custom element aa-journeys. Add it to your page like any other HTML element.

html
<aa-journeys></aa-journeys>

Then set its journeys property from JavaScript.

js
const cards = document.querySelector('aa-journeys')
cards.journeys = journeys

The journeys

journeys is an array of Journey or JourneyOffer objects, as the API returns them. Each one becomes a card, in the order of the array.

A card can only show the fields it is given, so ask for the ones in the example below. Keep __typename and the darkModeImage alias as written. The embed uses __typename to tell a stopover from a leg, and takes the logos for the dark theme from darkModeImage.

Example: A search with the fields a card shows

graphql
query Journeys {
  journeys(
    origin: { uid: "4X7ZaxZO" }
    destination: { uid: "ObB7ATsZ" }
    date: "2026-12-16"
  ) {
    id
    status
    itinerary {
      __typename
      ... on Stopover {
        duration
        location {
          name
        }
      }
      ... on SegmentCollection {
        status
        segments {
          ...Segment
        }
      }
    }
  }
}

fragment Segment on Segment {
  duration
  departureAt
  arrivalAt
  transport
  identifier
  direction
  co2 {
    value
    unit
  }
  operator {
    name
    image {
      url
    }
    darkModeImage: image(variant: DARK_MODE) {
      url
    }
  }
  serviceBrand {
    name
    image {
      url
    }
    darkModeImage: image(variant: DARK_MODE) {
      url
    }
  }
  amenities {
    category
    subCategory
    description
  }
  origin {
    name
  }
  destination {
    name
  }
}

To change the list, set a new array. The embed doesn't notice a change made inside the array it already has.

Prices

A journey from a search has no prices. To show them, give the embed the JourneyOffer you get from journeyOffer in the journey's place. It has the same fields as the journey, and the offers of each leg (SegmentCollection). The card shows the lowest price in 2nd class and in 1st class.

Example: A priced journey with the fields a card shows

graphql
query JourneyOffer {
  journeyOffer(
    journeyId: "25b7841e-5c89-4926-8c78-2dd127abdf88"
    passengers: [{ type: ADULT }]
  ) {
    id
    status
    itinerary {
      __typename
      ... on Stopover {
        duration
        location {
          name
        }
      }
      ... on SegmentCollection {
        status
        segments {
          ...Segment
        }
        offers {
          id
          memberOf {
            id
          }
          parts {
            __typename
            ... on AdmissionPart {
              serviceClass
              flexibility
              comfortClass
            }
            ... on ReservationPart {
              serviceClass
              flexibility
              comfortClass
              accommodation {
                type
                subType
              }
            }
          }
          price {
            amount
            currency
          }
        }
      }
    }
  }
}

fragment Segment on Segment {
  duration
  departureAt
  arrivalAt
  transport
  identifier
  direction
  co2 {
    value
    unit
  }
  operator {
    name
    image {
      url
    }
    darkModeImage: image(variant: DARK_MODE) {
      url
    }
  }
  serviceBrand {
    name
    image {
      url
    }
    darkModeImage: image(variant: DARK_MODE) {
      url
    }
  }
  amenities {
    category
    subCategory
    description
  }
  origin {
    name
  }
  destination {
    name
  }
}

Prices are shown in the currency of the offers. Use the currency argument of journeyOffer to choose it.

Attributes

Set these attributes on the <aa-journeys> element.

* = Required
Name Description Required
journeys The journeys to show. Set it as a property from JavaScript. As an attribute, it takes the same array as a JSON string. Yes
selectable Gives each card a button, so the user can select a journey. See below for details. This is a boolean attribute: add it to show the buttons, and remove it to make the cards read-only. No
selected The id of the selected journey offer. The embed sets it when the user selects a journey. Set it yourself to show a journey as selected, or remove it to clear the selection. It has no effect without selectable. No
language The language of the cards: en (the default), da, de, es, fr, nb or sv. No
theme The color theme: light (the default), dark, or auto, which follows the visitor's light or dark system setting. No

Selecting a journey

Without selectable, the cards are read-only. With it, each card has a button. What the button does depends on whether the journey has prices.

A journey without prices

The button says "Find tickets". The embed can't price the journey, so it asks your code to. When the user clicks, the embed emits aa-journeys-offer-request and the card shows a loading indicator.

Call journeyOffer with the journeyId from the event. Then set a new array, with the journey offer in the journey's place. The card shows the prices.

If the journey can't be priced, call endOfferRequest on the element with the same journeyId. The card gets its button back. Do this when the request fails, and when the journey offer comes back with no offers on any leg.

js
const cards = document.querySelector('aa-journeys')

cards.addEventListener('aa-journeys-offer-request', async (event) => {
  const { journeyId } = event.detail
  // Your own code, which calls journeyOffer where your API key is
  const journeyOffer = await getJourneyOffer(journeyId)

  const isPriced = journeyOffer?.itinerary.some((item) => item.offers?.length)
  if (!isPriced) return cards.endOfferRequest(journeyId)

  cards.journeys = cards.journeys.map((journey) =>
    journey.id === journeyId ? journeyOffer : journey
  )
})

A journey with prices

The button says "Select". When the user clicks, the embed emits aa-journeys-select and shows the card as selected. Use the journeyOfferId from the event to create a booking.

Events

Listen for the Journey Cards' events with addEventListener. They are only emitted with selectable.

Name Description
aa-journeys-offer-request Emitted when the user asks for the prices of a Journey. The event's detail has the journeyId.
aa-journeys-select Emitted when the user selects a JourneyOffer. The event's detail has the journeyOfferId, which you can use to create a booking.

Example

The demo gives the embed three stored journeys from Berlin to Zürich, and the first one is priced. Click "Find tickets" on another one. The demo answers after a moment with stored prices, where your code would call journeyOffer.