How to enter function googlesheets api?

Google Sheets API allows you to write values and formulas to cells, ranges, sets of ranges, and entire sheets. Functions can only be inserted through the cells feed. In this article we will show you how to enter function googlesheet api You can see an example below section. how exactly enter function googlesheet api.

What is an API?

API stands for “Application Program Interface”, and the term commonly refers to web URLs that can be used to access raw data. API stands for “Application Program Interface”, and the term commonly refers to web URLs that can be used to access raw data.


Steps to enter function google spreadsheet API:

Here we can use number api and connecting google sheets:

  1. First of all open a new google sheet.
  2. Go to Navigate to Tools > Script Editor.
number api example


3. Name the project: Numbers API Example where we’ll write our code.

4. Remove all the code that is currently in the Code.gs file, and replace it with this:

function callNumbers() {

// Call the Numbers API for random math fact
var response = UrlFetchApp.fetch(“http://numbersapi.com/random/math”);
Logger.log(response.getContentText());

}

We’re using the UrlFetchApp class to communicate with other applications on the internet to access resources, to fetch a URL.
Now your code window should look like this:

enter code

5. Run your function by clicking the play button in the toolbar:

6. Authorize your script to connect to an external service.

authorized required

7. View the logs. your program has now run.

8. Add data to Sheet.

function callNumbers() {

// Call the Numbers API for random math fact
var response = UrlFetchApp.fetch(“http://numbersapi.com/random/math”);
Logger.log(response.getContentText());

var fact = response.getContentText();
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange(1,1).setValue([fact]);

}

9. Run your program again. and click allow.
10. See external data in your sheet

external data on your data

11. Copy data into new cell

function callNumbers() {

// Call the Numbers API for random math fact
var response = UrlFetchApp.fetch(“http://numbersapi.com/random/math”);
Logger.log(response.getContentText());

var fact = response.getContentText();
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange(sheet.getLastRow() + 1,1).setValue([fact]);

}

Your output now will look like this:

output of code

12. Add the code for a custom menu

function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu(‘Custom Numbers API Menu’)
.addItem(‘Display random number fact’,’callNumbers’)
.addToUi();

}

Your final code for the Numbers API.

Hope this article is helpful to you.