how to extract data with airport schedule api

How to check Airport Schedule using Google Sheets and Airport Schedule API?

Finding flight schedules for an airport shouldn’t feel like searching for a needle in a haystack. But hopping between airline websites, refreshing pages, and manually compiling data? That’s a time-wasting nightmare.

What if you could get all that information directly in a Google Sheet—automatically? No coding, no complex setups—just a simple process that fetches real-time airline schedules in seconds.

In this guide, you’ll learn how to use Google Sheets and an API to extract airport schedules with ease. Follow the steps, set up your tool, and by the end, you’ll also get a blueprint sheet so you can plug in your details and get started instantly.

Let’s get to it. 

What You’ll Need:

  • FlightAPI’s Airport Schedule API 
  • Google Sheet

Step 1: Get Your API Key

  1. Sign up on FlightAPI.
  2. Verify your email to activate your account.
  3. Go to the dashboard and copy your API key from there.

Step 2: Create Google Sheet

  1. Open Google Sheets and create a new spreadsheet.
  2. Create a sheet named “input”:
    • In the first row, write “IATA” and make it bold.
    • Below this, enter the IATA codes of the airports you want to schedule data for.
  1. Create another sheet named “output” and leave it blank for now.

Step 3: Add the Apps Script to Google Sheets

Now that you have the required details, it’s time to insert the script into your Google Sheet. Follow these steps:

  1. Open your Google Sheet.
  2. Click on Extensions in the top menu.
  3. Select Apps Script from the dropdown. This will open a new tab with the Google Apps Script editor.
  4. In the left sidebar, click on Code.gs.
  5. Delete any existing code in the editor.
  6. Copy the below script and paste it into the editor.
function fetchAirportData() {

  var sheet = SpreadsheetApp.getActiveSpreadsheet();

  var inputSheet = sheet.getSheetByName("input");

  var outputSheet = sheet.getSheetByName("output");

  var apiKey = "MY API_KEY";

  var mode = "arrivals";

  var day = "1";

  // Get the range of IATA codes from the input sheet

  var iataRange = inputSheet.getRange(2, 1, inputSheet.getLastRow() - 1).getValues();

  // Prepare the output sheet

  outputSheet.clear();

  outputSheet.appendRow(["IATA Code", "Aircraft Name", "Scheduled Time of Arrival (Timestamp)", "Airline Name"]);  // Added IATA Code to the header

  // Loop over each IATA code and fetch data

  iataRange.forEach(function(row) {

    var iata = row[0];

    var apiUrl = `https://api.flightapi.io/schedule/${apiKey}?mode=${mode}&iata=${iata}&day=${day}`;

    try {

      var response = UrlFetchApp.fetch(apiUrl);

      var jsonData = JSON.parse(response.getContentText());

      jsonData.airport.pluginData.schedule.arrivals.data.forEach(function(flight) {

        var aircraftName = flight.flight.aircraft.model.text; // Ensure this path is correct

        var airlineName = flight.flight.airline.name; // Fetching airline name

        var scheduledArrivalTimestamp = flight.flight.time.scheduled.arrival; // Fetching the numeric timestamp directly

        outputSheet.appendRow([iata, aircraftName, scheduledArrivalTimestamp, airlineName]);

      });

    } catch (e) {

      console.error("Failed to fetch or parse data for IATA: " + iata + " with error: " + e.toString());

      // Optionally log to the sheet if error handling is needed within the sheet

      outputSheet.appendRow([iata, "Error fetching data for IATA: " + iata, "", ""]);

    }

  });

}

Step 3: Edit the Apps Script Code

1. Your API Key

  • In the script, find the line where the API key is defined.
  • Replace “My API_KEY” with your actual API key from FlightAPI.

2. Select the Date for Schedule Data

The API allows you to fetch schedules for yesterday, today, or tomorrow, using numerical values:

  • -1 → Yesterday
  • -2 → Day before yesterday
  • 1 → Today
  • 2 → Tomorrow

Add the numbers accordingly in the script here.

3. Choose Arrival or Departure Data

The API allows you to pull data for either:

“arrivals” → To get incoming flights

“departures” → To get outgoing flights

In the script, look for the mode and change it based on what you need.

If you need additional options or details about the API, check out the Airport Schedule API documentation.

Step 5: Save, Run the Script, and Check the Output

  1. After making the necessary edits to the API key, date, and mode, click on the disk icon (or press Ctrl + S) to save the script.
  1. At the top of the Apps Script editor, click on the Run button.
  2. The script will ask for permission the first time you run it. Click Review Permissions and allow access using your Google account.
  3. Once authorized, the script will execute and start pulling airport schedule data into your Google Sheet.
  4. Check the “output” sheet in your Google Sheet. If everything is set up correctly, you should see the flight data appear within a few seconds.

Download the Pre-Built Blueprint

No need to start from scratch—simply download the pre-built blueprint, make the necessary changes, and run the script to start fetching flight schedule data instantly. 

Click here to download your copy

Wrap Up:

With this Google Sheet blueprint, you can effortlessly track airport schedules. FlightAPI.io not only supports this functionality but also offers APIs for Flight Price API and Flight Status API, catering to various data needs.

If you’re looking to delve deeper into flight data extraction, whether through Python or no-code solutions, explore these additional resources to enhance your capabilities and streamline your data management processes.

Similar Posts