Madrid Barajas (MAD) Schedules API
You need to build reliable Madrid–Barajas Adolfo Suárez Airport (MAD) departure and arrival boards, itinerary planners, or alerting pipelines. By the end of this guide, you will be able to query Madrid Barajas schedules via FlightLabs, compare schedules with real-time status, and implement polling/caching strategies that keep your app responsive without wasting requests.
What “schedules” at MAD really means for your app
FlightLabs schedules let you retrieve planned departures and arrivals for Madrid Barajas (IATA: MAD). You can query by airport IATA code and direction (arrivals or departures) and receive structured JSON with the flight number, airline, planned departure and arrival times, and related operational details like terminals and aircraft. Use this feed to render airport boards, pre-build trip suggestions, or seed caches before augmenting with near-real-time updates.
When live status is required (e.g., “en-route,” “landed,” or gate changes), pair the schedules query with real-time flight tracking. For analytics and auditing, combine it with flight history. For planning ahead, consider the future flights dataset. The sections below compare these options and show how to implement a robust MAD integration.
Comparing ways to build MAD experiences with FlightLabs
There are several endpoints and datasets you can pair with schedules for Madrid Barajas, each serving a different lifecycle stage of a flight. Below is a technical comparison to help you choose:
| Dataset | Primary Use at MAD | Key Fields You’ll Use | Data Freshness | Typical Integration Pattern |
|---|---|---|---|---|
| Flight Schedules | Build departure/arrival boards; plan daily operations | flight_number; departure.scheduled; arrival.scheduled; airline.*; aircraft.*; terminals if provided | Planned data | Poll periodically (e.g., every 15–30 min) and cache |
| Real-time Flight Tracking | Overlay live status (en-route, delays, gates) on top of schedules | flight.status; departure.actual; arrival.estimated; terminal; gate; position.* | Near real time | Poll selectively for flights within a time window (e.g., T-3h to +1h) |
| Flight History | Post-event analytics; performance dashboards | Historical timings and metadata similar to real-time | Finalized historical data | Batch fetch off-peak; archive |
| Future Flights | Trip building and long-range planning for MAD | Future schedule-like attributes | Planned, long-horizon | Low-frequency sync (e.g., daily) |
Reference pages for these datasets are available on Documentation. You can also explore and test requests in the MCP console.
Requesting Madrid Barajas schedules by IATA code
Schedules are retrieved from the FlightLabs base API using the schedules path and two key parameters:
- iataCode: the airport code, set to MAD
- type: either arrival or departure
Example: query MAD departures with a single GET call.
curl -G "https://api.goflightlabs.com/flights-schedules" \
--data-urlencode "iataCode=MAD" \
--data-urlencode "type=departure" \
--data-urlencode "access_key=YOUR_API_KEY"
Replace YOUR_API_KEY with your actual key. If you don’t have one yet, you can Register for a 7-day or 50-request trial. A Starter plan is available at $24.99/month when you’re ready to ship.
Parse and display MAD schedules in JavaScript
Below is a minimal JavaScript example that queries Madrid departures, extracts the fields that typically matter for boards and planners, and prints a simple summary. Adjust the rendering logic to suit your UI (e.g., tables or tiles).
async function fetchMadDepartures() {
const params = new URLSearchParams({
iataCode: "MAD",
type: "departure",
access_key: "YOUR_API_KEY"
});
const res = await fetch(`https://api.goflightlabs.com/flights-schedules?${params.toString()}`);
if (!res.ok) {
throw new Error(`HTTP ${res.status}: ${await res.text()}`);
}
const json = await res.json();
// Expected shape aligns with the schedules example in the docs
const schedules = json?.data?.schedules || [];
// Transform for a basic board
return schedules.map((item) => {
const flightNumber = item.flight_number;
const airline = item.airline?.name || item.airline?.iata || "Unknown Airline";
const depAirport = item.departure?.airport;
const depTimeUtc = item.departure?.scheduled; // UTC timestamps end with Z
const depTerminal = item.departure?.terminal;
const arrAirport = item.arrival?.airport;
const arrTimeUtc = item.arrival?.scheduled;
const arrTerminal = item.arrival?.terminal;
const aircraftType = item.aircraft?.type;
return {
flightNumber,
airline,
depAirport,
depTimeUtc,
depTerminal,
arrAirport,
arrTimeUtc,
arrTerminal,
aircraftType
};
});
}
fetchMadDepartures()
.then((rows) => {
for (const r of rows) {
console.log(
[
r.flightNumber,
r.airline,
`Dep ${r.depAirport} @ ${r.depTimeUtc} T${r.depTerminal || "-"}`,
`Arr ${r.arrAirport} @ ${r.arrTimeUtc} T${r.arrTerminal || "-"}`,
r.aircraftType || ""
].join(" | ")
);
}
})
.catch((err) => {
console.error("Failed to load MAD departures:", err);
});
Official schedule payload example and what to read
The schedule payload below is an official example with the fields you’ll commonly use to render MAD listings. Times are in UTC (notice the trailing Z). Terminals may be provided when available.
{
"success": true,
"data": {
"schedules": [
{
"flight_number": "UA456",
"departure": {
"airport": "SFO",
"scheduled": "2024-03-20T08:00:00Z",
"terminal": "3"
},
"arrival": {
"airport": "ORD",
"scheduled": "2024-03-20T14:15:00Z",
"terminal": "1"
},
"aircraft": {
"type": "Boeing 787-9",
"registration": "N123UA"
},
"airline": {
"name": "United Airlines",
"iata": "UA"
}
}
]
}
}
Key fields to use in MAD contexts:
- flight_number: Your primary display string. Combine with airline.iata or airline.name when branding is shown.
- departure.scheduled and arrival.scheduled: Planned UTC timestamps. Convert to Europe/Madrid when needed.
- departure.terminal and arrival.terminal: Useful for signage; may not always be present.
- aircraft.type and aircraft.registration: Shown in enthusiast apps and ops consoles.
- airline.name and airline.iata: Airline label and filtering.
Note: Codeshare indicators are not shown in this sample. If your plan includes codeshare fields, group and present partner flight numbers together in the UI to avoid duplication. If not available, you can still deduplicate by aligning on departure/arrival pairings and planned times.
Layering real-time status on top of MAD schedules
Schedules are best-effort plans; travelers and operations need live status and gate changes as the day unfolds. Pair your MAD schedules cache with real-time tracking for flights that are close to departure or arrival windows. Here is the official real-time example schema to illustrate the status fields you’ll integrate:
{
"success": true,
"data": {
"flight": {
"iata": "AA123",
"icao": "AAL123",
"number": "123",
"status": "en-route",
"departure": {
"airport": "JFK",
"scheduled": "2024-03-20T10:00:00Z",
"actual": "2024-03-20T10:05:00Z",
"terminal": "8",
"gate": "B12"
},
"arrival": {
"airport": "LAX",
"scheduled": "2024-03-20T13:15:00Z",
"estimated": "2024-03-20T13:20:00Z",
"terminal": "4",
"gate": "45A"
},
"position": {
"latitude": 39.8729,
"longitude": -98.7372,
"altitude": 35000,
"speed": 495,
"heading": 270
}
}
}
}
How to use these fields for MAD:
- flight.status: Display “scheduled,” “en-route,” “landed,” “canceled,” or similar values as the primary status line.
- departure.actual and arrival.estimated: Compare against scheduled for live delay deltas (e.g., ETA drift into MAD).
- terminal and gate: Override the scheduled/boarded gate and terminal with current assignments to reduce confusion.
- position.*: Optionally show a live map for inbound flights to MAD or draw a progress bar.
When a flight is canceled or diverted, status will indicate such a state. For diverted flights affecting MAD arrivals, treat them as removed from your arrivals board or annotate with a strong “Diverted” label and the latest known information. Keep your schedules cache intact for audit history but filter your live view using the real-time status overlay.
Time zones at MAD and converting UTC safely
Schedule and real-time timestamps are returned in UTC (“Z”). Madrid Barajas operates in the Europe/Madrid time zone. If you need local display, convert UTC to the airport’s local time. You can detect or store the airport’s time zone from airport metadata when available. The official airport data example demonstrates the kind of fields you might use for this purpose:
{
"success": true,
"data": {
"airport": {
"iata": "JFK",
"icao": "KJFK",
"name": "John F. Kennedy International Airport",
"location": {
"lat": 40.6413,
"lon": -73.7781,
"city": "New York",
"country": "United States"
},
"timezone": "America\/New_York",
"terminals": [
"1",
"2",
"4",
"5",
"7",
"8"
],
"runways": [
{
"length_ft": 14511,
"width_ft": 150,
"surface": "concrete",
"designator": "13L\/31R"
}
],
"weather": {
"temp_c": 22,
"visibility_km": 10,
"wind": {
"speed_kts": 8,
"direction_deg": 180
}
}
}
}
}
In your MAD apps, convert from UTC to Europe/Madrid for user-facing displays, but store and compare using UTC to avoid DST pitfalls. If your app supports multi-airport itineraries, always show local time per segment and label it clearly (e.g., “Local time MAD”).
Polling, caching, and pagination strategies for MAD schedules
Polling frequency
- Schedules: For a single-airport MAD board, polling every 15–30 minutes is typically sufficient. Cache the JSON response to reduce request volume.
- Real-time overlays: Only poll for flights within a relevant time window, e.g., departures within the next 3 hours or arrivals within the last 1 hour plus next 2 hours. Increase frequency to every 2–5 minutes for those flights.
Caching
- Cache schedules keyed by iataCode=MAD and type=arrival|departure along with a retrieval timestamp.
- In your cache layer, update in place and incrementally reconcile with real-time events (e.g., status changes, adjusted gates).
- Use ETag/If-Modified-Since if supported in your environment, or simply apply a TTL and diff old vs. new responses by flight_number and scheduled times.
Pagination
- If the schedules response is large, consult the Documentation for available pagination parameters and patterns. If no explicit pagination parameters are provided for your plan, consider segmenting your requests by time slices (e.g., per hour blocks) to bound payload sizes.
Error handling and retries
- Handle non-200 responses gracefully with exponential backoff. Log request IDs and timestamps for auditing.
- Fail open in the UI with the last known cached schedules and clearly label the refresh time to avoid surprising users.
Building common MAD features with schedules + status
Departure board for MAD
- Base list: Query /flights-schedules with iataCode=MAD and type=departure. Sort by departure.scheduled UTC.
- Status overlay: For flights within the next 180 minutes, fetch real-time status and replace scheduled with actual/estimated as available. Show terminal/gate when returned.
- Display logic: If real-time shows canceled, render the row with a clear “Canceled” badge and optionally collapse it after a grace period.
Arrivals monitor for ground ops
- Base list: Query /flights-schedules with iataCode=MAD and type=arrival for the current day’s window.
- Live updates: For imminent arrivals, read flight.status and arrival.estimated to adjust stand assignment timing and resource planning.
- Diversions: If status indicates diversion, remove from predicted arrival queue and alert downstream systems.
Corporate travel or analytics tools
- Planning view: Pull schedules and future flights for the next 2–7 days into a read-through cache.
- Day-of-travel: For booked segments touching MAD, overlay live status updates (status, estimated, gates) and push notifications on change.
- Analysis: Pair with flight history for retrospective reporting.
Authentication, testing, and going live
All calls are authenticated with your FlightLabs API key. Start by signing up for a trial and testing your MAD queries end-to-end in your development environment. Use the MCP to explore query patterns and confirm the fields available to your plan. When you’re ready, the Starter plan is $24.99/month. See the Documentation for endpoint details and production nuances.
Practical field notes for Madrid Barajas integrations
- Terminals at MAD: Terminals in schedules and real-time data may differ as operations evolve through the day. Always let the real-time terminal/gate override the scheduled one when present.
- Delays: There is no explicit delay field in the schedule example. Compute delays as the delta between real-time actual/estimated and scheduled when you have both.
- Codeshares: If your response includes codeshare indicators in your plan, show the primary marketing carrier then list alternates. If not available, reduce duplication by grouping on identical scheduled times and airports with the same equipment.
- Time math: Keep all internal comparisons in UTC; only convert to Europe/Madrid at the rendering edge. Label times clearly to avoid ambiguity.
FAQ
How do I retrieve only MAD departures?
Call the schedules endpoint with iataCode=MAD and type=departure. Use the example curl above as a template and cache the result for 15–30 minutes.
What’s the best way to show live gates and delays?
Use schedules for the base list, then query real-time for flights within a short time window around departure/arrival. Prefer real-time terminal/gate and actual/estimated times over scheduled when both are present.
How should I handle local time in Madrid?
All timestamps are UTC in the examples. Convert to Europe/Madrid for displays, but store and compare in UTC. If you maintain airport metadata, map MAD to its local time zone and annotate labels (e.g., “Local time MAD”).
What if a flight is canceled or diverted?
Use the real-time flight.status to detect cancellations or diversions and reflect that immediately in your UI. Keep the scheduled record in your cache for history, but filter the live view accordingly.
How do I paginate a full day of MAD schedules?
If explicit pagination parameters are available to your plan, follow the documentation. Otherwise, request schedules in time slices (e.g., hourly) to bound payload size, and merge results in your cache keyed by flight_number and scheduled time.
Ready to integrate Madrid Barajas schedules into your product? Get your API key and start building today: Register. Consult the Documentation and explore endpoints interactively in MCP to ship faster.