Sample Data
This sheet lists User IDs in column A. We want to fetch User Names from an API using Apps Script.
| Cell | Value |
|---|---|
| A1 | User ID |
| B1 | User Name |
| A2 | 123 |
| A3 | 456 |
| A4 | 789 |
Jump into concepts and practice - no test required
This sheet lists User IDs in column A. We want to fetch User Names from an API using Apps Script.
| Cell | Value |
|---|---|
| A1 | User ID |
| B1 | User Name |
| A2 | 123 |
| A3 | 456 |
| A4 | 789 |
fetchUserName(123)A B 1 User ID User Name 2 123 Alice 3 456 Bob 4 789 Carol
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.