Chapter 16. External APIs and Integration

Accessing external APIs, whether Google APIs or some other resource, is generally very easy. The Google infrastructure is super-fast, and accessing Internet services works at Google speed because Apps Script runs on that infrastructure. In previous examples, this kind of external data connectivity has been demonstrated a few times, but it’s such a strong Apps Script capability that it’s worth dedicating a few pages to it.

This chapter will demonstrate how to use the UrlFetchApp service to interact with:

A REST service
Get data and populate a spreadsheet with the results.
A NoSQL database
Use Firebase from Apps Script.

The UrlFetchApp service is somewhat equivalent to the VBA serverXMLHTTP object, but has a much simpler approach to headers and options.

REST API

This example will interact with the FAA (Federal Aviation Authority) API, to see if there are any current delays at selected US airports. Given an airport (IATA) code, this API returns data like this:

{ delay: "false", IATA: "EWR", state: "New Jersey", name: "Newark International", weather: { visibility: 10, weather: "A Few Clouds", meta: { credit: "NOAA's National Weather Service", updated: "5:51 AM Local", url: "http://weather.gov/" }, temp: "62.0 F (16.7 C)", wind: "Northeast at 4.6mph" }, ICAO: "Kewr", city: "Newark", status: { reason: "No known delays for this airport.", closureBegin: "", endTime: "", minDelay: "", avgDelay: "", maxDelay: "", closureEnd: "", trend: "", type: ...

Get Going GAS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.