Google Apps Script can fetch data from external APIs and populate your Google Sheets. Here’s how:
Step-by-Step Guide:
- Open the Script Editor:
- Navigate to
Extensions > Apps Script
.
- Navigate to
- Write the API Fetch Script:
function fetchData() {
var url = ‘https://api.example.com/data’;
var response = UrlFetchApp.fetch(url);
var data = JSON.parse(response.getContentText());
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
sheet.getRange(1, 1, data.length, data[0].length).setValues(data);
}
- Run the Script:
- Save and run the
fetchData
function.
- Save and run the
Explanation:
- URL Fetch: Uses
UrlFetchApp
to fetch data from the API. - JSON Parsing: Parses the JSON response and writes it to the sheet.