Dashboard Mode - API calls from Apps Script
Goal
See how to fetch live data from a web API into Google Sheets using Apps Script and analyze it in a dashboard.
Jump into concepts and practice - no test required
See how to fetch live data from a web API into Google Sheets using Apps Script and analyze it in a dashboard.
| City | Temperature (°C) | Humidity (%) | Condition |
|---|---|---|---|
| New York | 22 | 60 | Clear |
| London | 18 | 75 | Cloudy |
| Tokyo | 25 | 70 | Rain |
| Sydney | 20 | 65 | Clear |
| Mumbai | 30 | 80 | Sunny |
=AVERAGE(B2:B6)=MAX(C2:C6)fetchWeatherData()+----------------------+----------------------+ | Average Temperature | Highest Humidity | | (KPI) | (KPI) | +----------------------+----------------------+ | | | Weather Data Table | | | +----------------------------------------------+
User clicks a custom menu button in Google Sheets to run the fetchWeatherData() script. This updates the weather data table with fresh API data. The KPI cards automatically recalculate based on the updated data.
If you add a filter to show only cities with temperature above 20°C, which components update?
UrlFetchApp.fetch() function do in Google Apps Script?response.getContentText() to get the response as a string.JSON.parse() to convert the string into a usable JavaScript object.var response = UrlFetchApp.fetch('https://api.example.com/data');
var json = JSON.parse(response.getContentText());
Logger.log(json.status);
Assuming the API returns {"status":"success","count":10}.json.status outputs the string "success".var response = UrlFetchApp.fetch('https://api.example.com/data');
var data = JSON.parse(response);
Logger.log(data.message);response.getContentText() to get the response as a string before parsing.UrlFetchApp.fetch() to get the response, then parse it with JSON.parse(response.getContentText()) to get the data object.SpreadsheetApp.getActiveSheet().getRange('A1').setValue(data.temperature) to set the cell value.