0
0
Google Sheetsspreadsheet~20 mins

API calls from Apps Script in Google Sheets - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
API Calls Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📊 Formula Result
intermediate
2:00remaining
What is the output of this Apps Script API call?
Consider this Apps Script code snippet that calls a public API and writes the result to a Google Sheet cell:

function fetchJoke() {
  var response = UrlFetchApp.fetch('https://official-joke-api.appspot.com/random_joke');
  var joke = JSON.parse(response.getContentText());
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  sheet.getRange('A1').setValue(joke.setup + ' - ' + joke.punchline);
}

What will be the content of cell A1 after running fetchJoke()?
Google Sheets
function fetchJoke() {
  var response = UrlFetchApp.fetch('https://official-joke-api.appspot.com/random_joke');
  var joke = JSON.parse(response.getContentText());
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  sheet.getRange('A1').setValue(joke.setup + ' - ' + joke.punchline);
}
ACell A1 remains empty because setValue is missing
BThe raw JSON string from the API response in cell A1
CA random joke's setup and punchline combined as a single string in cell A1
DAn error message because UrlFetchApp is not defined
Attempts:
2 left
💡 Hint
Think about what JSON.parse does and how setValue works.
Function Choice
intermediate
1:30remaining
Which Apps Script function correctly retrieves JSON data from an API?
You want to get JSON data from a public API in Google Apps Script. Which function call correctly fetches and parses the JSON?
Avar response = UrlFetchApp.fetch(url); var data = JSON.parse(response.getContentText());
Bvar data = UrlFetchApp.getJSON(url);
Cvar response = UrlFetchApp.get(url); var data = response.json();
Dvar data = fetch(url).json();
Attempts:
2 left
💡 Hint
Check the official Apps Script methods for fetching URLs and parsing JSON.
🎯 Scenario
advanced
2:00remaining
You want to update multiple cells with API data efficiently
You have an API that returns an array of user names. You want to write these names into cells A1:A5 in your Google Sheet using Apps Script. Which approach is best for performance?
AWrite names one by one using sheet.appendRow(name)
BCall UrlFetchApp.fetch multiple times, once per name
CCall sheet.getRange('A1').setValue(name) inside a loop for each name
DBuild a 2D array of names and call sheet.getRange('A1:A5').setValues(array) once
Attempts:
2 left
💡 Hint
Think about minimizing calls to the spreadsheet service.
📊 Formula Result
advanced
1:30remaining
What error occurs with this Apps Script API call?
What error will this Apps Script code produce?

function getData() {
  var response = UrlFetchApp.fetch('https://api.example.com/data');
  var data = JSON.parse(response);
  Logger.log(data);
}
Google Sheets
function getData() {
  var response = UrlFetchApp.fetch('https://api.example.com/data');
  var data = JSON.parse(response);
  Logger.log(data);
}
ATypeError because JSON.parse expects a string but gets an HTTPResponse object
BSyntaxError due to invalid JSON format
CNo error, logs parsed JSON data
DReferenceError because UrlFetchApp is undefined
Attempts:
2 left
💡 Hint
Check what UrlFetchApp.fetch returns and what JSON.parse expects.
data_analysis
expert
2:00remaining
How many items are in the array returned by this API call?
This Apps Script code fetches data from an API and parses it:

function countItems() {
  var response = UrlFetchApp.fetch('https://jsonplaceholder.typicode.com/posts');
  var posts = JSON.parse(response.getContentText());
  return posts.length;
}

What is the value returned by countItems()?
Google Sheets
function countItems() {
  var response = UrlFetchApp.fetch('https://jsonplaceholder.typicode.com/posts');
  var posts = JSON.parse(response.getContentText());
  return posts.length;
}
A200
B100
C50
DUndefined because posts is not an array
Attempts:
2 left
💡 Hint
Check the API documentation or test the URL in a browser.