In this API instructional exercise for beginners, you'll figure out how to interface with APIs utilizing Google Apps Script, to recover information from an outsider and show it in your
By Kate Angelou
In this API instructional exercise for beginners, you'll figure out how to interface with APIs utilizing Google Apps Script, to recover information from an outsider and show it in your Google Sheet.
IT will tells you the best way to utilize Google Apps Script to interface with a basic API to recover some information and show it in Google Sheets:
The goal here is to take an in-depth look at deploying API's over google spreadsheet using script editor. To find script editor , go to tools > script editor
You will find a script editor console here, which will have a predefined function. On the right side, you will have the option of a file in which you can insert as many files as you want.
Now let's see by assigning Api inside the function,
var url = "YOUR_API_URI"
var response = UrlFetchApp.fetch(url)
var data = response.getContentText()
var result = JSON.parse(data);
This is where you need to console. You can use this function that will show you the response Logger.log(var_name);
Logger.log() is same as like console.log(), But here it won't depicts respond in your browser.
It will return result in a window which will be below at your editor named as Execution Log.
After parsing, you now have to link the spreadsheet in which to print the result. For which use below method
var ss = SpreadsheetApp.getActiveSheet();
Create a header if you want to assign a header, And append to spreadsheet
var headerRow = ["Title", "Impressions", "Clicks", "Revenue","Date","Time"] ss.appendRow(headerRow)
Now run the loop by printing the results you want.