Challenge - 5 Problems
API Calls Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📊 Formula Result
intermediate2: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:
What will be the content of cell A1 after running
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);
}Attempts:
2 left
💡 Hint
Think about what JSON.parse does and how setValue works.
✗ Incorrect
The code fetches a random joke JSON, parses it, then writes the combined setup and punchline as a string into cell A1.
❓ Function Choice
intermediate1: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?
Attempts:
2 left
💡 Hint
Check the official Apps Script methods for fetching URLs and parsing JSON.
✗ Incorrect
Only UrlFetchApp.fetch returns a response object with getContentText(), which can be parsed by JSON.parse.
🎯 Scenario
advanced2: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?
Attempts:
2 left
💡 Hint
Think about minimizing calls to the spreadsheet service.
✗ Incorrect
Calling setValues once with a 2D array is much faster than multiple setValue calls inside a loop.
📊 Formula Result
advanced1: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);
}Attempts:
2 left
💡 Hint
Check what UrlFetchApp.fetch returns and what JSON.parse expects.
✗ Incorrect
UrlFetchApp.fetch returns an HTTPResponse object, not a string. JSON.parse needs a string, so passing the object causes a TypeError.
❓ data_analysis
expert2: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:
What is the value returned by
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;
}Attempts:
2 left
💡 Hint
Check the API documentation or test the URL in a browser.
✗ Incorrect
The API returns an array of 100 post objects, so posts.length is 100.