Query Anything by ID
Many objects in the API have unique IDs and implement the Node interface. This lets you fetch any object by its ID using a single query pattern, even if you don't know what type it is.
When to use it
When you create a booking or order, you get an ID back. Later, you might need to fetch that booking or order to check its status or retrieve tickets. Instead of remembering different query patterns for each type, you can use the node query for everything.
This is especially useful when:
- Storing IDs in your database and fetching them later
- Building generic UI components that work with any object type
- Fetching objects from webhooks or callbacks where you only have an ID
How it works
Objects that implement Node have a unique id field. You can fetch any of these objects using the node query by providing the ID:
query {
node(id: "some-id-here") {
# Query fields here
}
}Since node can return any type that implements Node, you need to use inline fragments (... on TypeName) to specify which type you're expecting and what fields you want. See the GraphQL documentation for details.
Examples
Fetching a booking
If you have a booking ID and want to check its status:
Example: Get booking by ID
query GetBooking {
node(id: "booking_66p1m4f270j171x2m6g30282k3") {
... on Booking {
id
selections {
... on JourneyOfferSelection {
offers {
id
price {
amount
currency
}
parts {
... on AdmissionPart {
conditions {
__typename
description
}
flexibility
serviceClass
comfortClass
}
... on ReservationPart {
conditions {
__typename
description
}
flexibility
comfortClass
accommodation {
type
}
}
}
}
}
}
}
}
}Fetching an offer
If you stored an offer ID and want to fetch its details:
Example: Get offer by ID
query GetOffer {
node(id: "offer_n0g22075r0y216r632z4h101r5") {
... on Offer {
id
price {
amount
currency
}
parts {
... on AdmissionPart {
flexibility
serviceClass
comfortClass
}
... on ReservationPart {
flexibility
comfortClass
accommodation {
type
}
}
}
}
}
}Fetching an order
The most common use case is fetching an order to retrieve tickets or pass codes:
query GetOrder {
node(id: "order_70g7f594z356y5v6h5y6r3b5s5") {
... on Order {
id
status
items {
# Get tickets or pass codes
}
}
}
}Available node types
The following types implement the Node interface and can be fetched using the node query:
AccessTokenBlueprintJourneyBookingBookingFareJourneyFareJourneyOfferNoChargeRedirectNonStopJourneyOfferOrderPassBundlePassengerProfilePlacePreferenceRefundSelectedFareSmartJourneyStripePayment
Best practices
-
Store IDs: When you create bookings, orders, or other objects, store the IDs in your database for later retrieval.
-
Use specific fragments: Always use inline fragments (
... on TypeName) to specify the expected type and request only the fields you need. -
Handle errors: If an ID doesn't exist or is invalid, the query will return null. Handle this gracefully in your code.
-
Check types: If you're not sure what type an ID represents, you can query the
__typenamefield to identify it.