async def get_order(params: GetOrderInput) -> str:
"""
Retrieve complete details for an existing flight order.
This tool fetches:
- Order status and booking reference
- Flight itinerary and schedule
- Passenger information
- Payment and pricing details
- Documents and tickets
- Change and cancellation options
Use this when:
- User needs to review their booking
- Checking order status
- Before making changes or cancellations
- Retrieving booking reference for airline website
Returns order details in specified format (JSON or Markdown).
"""
try:
response = await make_api_request(
method="GET",
endpoint=f"/air/orders/{params.order_id}"
)
order = response["data"]
if params.response_format == ResponseFormat.JSON:
return truncate_text(format_json_response(order))
else: # Markdown format
lines = [
"# Flight Order Details",
"",
f"**Order ID**: `{order['id']}`",
f"**Booking Reference**: {order.get('booking_reference', 'N/A')}",
f"**Status**: {order.get('status', 'N/A')}",
f"**Total**: {format_currency(order['total_amount'], order['total_currency'])}",
f"**Booked**: {order.get('created_at', 'N/A')}",
"",
"## Passengers"
]
for i, pax in enumerate(order.get("passengers", []), 1):
lines.append(f"{i}. {pax.get('given_name')} {pax.get('family_name')}")
if pax.get('born_on'):
lines.append(f" - DOB: {pax['born_on']}")
lines.append("")
lines.append("## Flight Itinerary")
for i, slice_info in enumerate(order.get("slices", []), 1):
origin = slice_info["origin"]
destination = slice_info["destination"]
lines.append(f"\n### Slice {i}: {origin['city_name']} → {destination['city_name']}")
lines.append(f"**Departure**: {slice_info['departure_at']} ({origin['iata_code']})")
lines.append(f"**Arrival**: {slice_info['arrival_at']} ({destination['iata_code']})")
lines.append(f"**Duration**: {format_duration(slice_info.get('duration', ''))}")
for j, segment in enumerate(slice_info.get("segments", []), 1):
carrier = segment.get("marketing_carrier", {})
lines.append(f"\n**Flight {j}**: {carrier.get('name', 'N/A')} {segment.get('marketing_carrier_flight_number', '')}")
lines.append(f"- Aircraft: {segment.get('aircraft', {}).get('name', 'N/A')}")
conditions = order.get("conditions", {})
if conditions:
lines.append("\n## Booking Conditions")
change_before = conditions.get("change_before_departure", {})
if change_before:
allowed = "✅ Yes" if change_before.get("allowed") else "❌ No"
lines.append(f"- Changes before departure: {allowed}")
if change_before.get("penalty_amount"):
penalty = format_currency(
change_before["penalty_amount"],
change_before.get("penalty_currency", "")
)
lines.append(f" - Change fee: {penalty}")
refund_before = conditions.get("refund_before_departure", {})
if refund_before:
allowed = "✅ Yes" if refund_before.get("allowed") else "❌ No"
lines.append(f"- Refund before departure: {allowed}")
return truncate_text("\n".join(lines))
except Exception as e:
return f"Error retrieving order: {str(e)}\n\nTroubleshooting:\n- Verify the order ID is correct (starts with 'ord_')\n- Check if you have access to this order\n- Order might not exist or might have been cancelled"