Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the purpose of using API calls in Google Apps Script?
API calls let your script talk to other web services to get or send data automatically, like fetching weather info or sending emails without manual work.
Click to reveal answer
beginner
Which Apps Script service is used to make HTTP requests to APIs?
The UrlFetchApp service is used to send HTTP requests like GET or POST to APIs and get responses back.
Click to reveal answer
beginner
How do you send a GET request to an API using Apps Script?
Use UrlFetchApp.fetch(url) where url is the API endpoint. This sends a GET request and returns the response.
Click to reveal answer
intermediate
What is the role of the 'options' object in UrlFetchApp.fetch(url, options)?
The options object lets you set method (GET, POST), headers, payload, and other settings to customize your API request.
Click to reveal answer
beginner
Why should you parse the API response in Apps Script, and how is it done?
API responses are often in JSON text. You parse them with JSON.parse(response.getContentText()) to turn them into usable objects in your script.
Click to reveal answer
Which Apps Script service do you use to call an external API?
AUrlFetchApp
BSpreadsheetApp
CDriveApp
DMailApp
✗ Incorrect
UrlFetchApp is the service designed to make HTTP requests to external APIs.
What HTTP method does UrlFetchApp.fetch(url) use by default?
AGET
BPUT
CPOST
DDELETE
✗ Incorrect
By default, fetch() sends a GET request unless you specify otherwise in options.
How do you include headers in an API request using UrlFetchApp?
AUse SpreadsheetApp.setHeaders()
BInclude headers in the URL string
CHeaders are not supported
DAdd a headers object inside the options parameter
✗ Incorrect
Headers are added inside the options object as a headers property.
What is the correct way to parse a JSON response from an API in Apps Script?
AJSON.stringify(response)
Bresponse.getText()
CJSON.parse(response.getContentText())
Dresponse.toString()
✗ Incorrect
You use JSON.parse() on the text content of the response to get a JavaScript object.
Which option is NOT a valid HTTP method you can use in UrlFetchApp options?
APOST
BFETCH
CGET
DPUT
✗ Incorrect
FETCH is not an HTTP method; valid methods include GET, POST, PUT, DELETE, etc.
Explain how to make a POST API call from Google Apps Script and handle the JSON response.
Think about setting method, headers, payload, and parsing the response.
You got /4 concepts.
Describe the steps to fetch data from a public API and insert it into a Google Sheet using Apps Script.
Focus on fetching, parsing, and writing data to the sheet.
You got /4 concepts.
Practice
(1/5)
1. What does the UrlFetchApp.fetch() function do in Google Apps Script?
easy
A. It deletes data from a sheet.
B. It creates a new Google Sheet.
C. It formats cells in a spreadsheet.
D. It sends a request to an external API and gets a response.
Solution
Step 1: Understand the purpose of UrlFetchApp.fetch()
This function is used to send HTTP requests to external services or APIs.
Step 2: Identify what it returns
It returns the response from the API, which can be text, JSON, or other data formats.
Final Answer:
It sends a request to an external API and gets a response. -> Option D
Quick Check:
UrlFetchApp.fetch() = Sends API request [OK]
Hint: Remember: fetch means get data from outside [OK]
Common Mistakes:
Thinking it modifies spreadsheet data directly
Confusing it with sheet creation functions
Assuming it formats cells
2. Which of the following is the correct way to parse a JSON response from an API call in Apps Script?
easy
A. var data = response.toString();
B. var data = response.getJson();
C. var data = JSON.parse(response.getContentText());
D. var data = JSON.stringify(response);
Solution
Step 1: Identify how to get text from response
Use response.getContentText() to get the response as a string.
Step 2: Parse JSON string to object
Use JSON.parse() to convert the string into a usable JavaScript object.
Final Answer:
var data = JSON.parse(response.getContentText()); -> Option C
Quick Check:
Parse JSON with JSON.parse(getContentText()) [OK]
Hint: Use JSON.parse on getContentText() result [OK]
Common Mistakes:
Using JSON.stringify instead of JSON.parse
Trying to call getJson() which doesn't exist
Not converting response to text first
3. Given this Apps Script code snippet, what will be logged?
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}.
medium
A. 10
B. success
C. {"status":"success","count":10}
D. undefined
Solution
Step 1: Parse the JSON response
The response text is parsed into an object: {status: "success", count: 10}.
Step 2: Access the 'status' property
Logging json.status outputs the string "success".
Final Answer:
success -> Option B
Quick Check:
json.status = "success" [OK]
Hint: Access JSON properties after parsing response [OK]
Common Mistakes:
Logging the whole JSON string instead of property
Confusing count with status
Not parsing JSON before accessing properties
4. What is wrong with this Apps Script code snippet?
var response = UrlFetchApp.fetch('https://api.example.com/data');
var data = JSON.parse(response);
Logger.log(data.message);
medium
A. You must parse response.getContentText(), not response directly.
B. Logger.log cannot print JSON data.
C. UrlFetchApp.fetch() requires a second parameter.
D. JSON.parse cannot be used in Apps Script.
Solution
Step 1: Check what is passed to JSON.parse()
The code passes the whole response object, but JSON.parse expects a string.
Step 2: Correct usage
Use response.getContentText() to get the response as a string before parsing.
Final Answer:
You must parse response.getContentText(), not response directly. -> Option A
Quick Check:
Parse string, not response object [OK]
Hint: Always parse response.getContentText() [OK]
Common Mistakes:
Passing response object directly to JSON.parse
Thinking Logger.log can't print objects
Assuming fetch needs extra parameters always
5. You want to fetch weather data from an API and write the temperature into cell A1 of your Google Sheet. Which Apps Script code correctly does this?
hard
A. var response = UrlFetchApp.fetch('https://api.weather.com/temp');
var data = JSON.parse(response.getContentText());
SpreadsheetApp.getActiveSheet().getRange('A1').setValue(data.temperature);
B. var response = UrlFetchApp.fetch('https://api.weather.com/temp');
var data = response.getContentText();
SpreadsheetApp.getActiveSheet().getRange('A1').setValue(data.temperature);
C. var response = UrlFetchApp.fetch('https://api.weather.com/temp');
var data = JSON.stringify(response);
SpreadsheetApp.getActiveSheet().getRange('A1').setValue(data.temperature);
D. var response = UrlFetchApp.fetch('https://api.weather.com/temp');
SpreadsheetApp.getActiveSheet().getRange('A1').setValue(response);
Solution
Step 1: Fetch and parse the API response
Use UrlFetchApp.fetch() to get the response, then parse it with JSON.parse(response.getContentText()) to get the data object.
Step 2: Write the temperature value to cell A1
Use SpreadsheetApp.getActiveSheet().getRange('A1').setValue(data.temperature) to set the cell value.
Final Answer:
var response = UrlFetchApp.fetch('https://api.weather.com/temp');
var data = JSON.parse(response.getContentText());
SpreadsheetApp.getActiveSheet().getRange('A1').setValue(data.temperature); -> Option A
Quick Check:
Fetch, parse JSON, write value to sheet [OK]
Hint: Parse JSON then set cell value with setValue() [OK]