function myFunction() {
var url = 'https://api.github.com/users/chaimf90/repos'
var response = UrlFetchApp.fetch(url);
var json = response.getContentText();
var data = JSON.parse(json)
var sheet = SpreadsheetApp.getActiveSheet();
sheet.appendRow(['Repo Name', data[0].name]);
}
When I execute this function from the script editor it runs as expected, but when I try to call this function in the sheet itself by calling =myFunction()
, I get an error saying that I do not have permission to call appendRow
.
Why can I call this function from the script editor, but not from the sheet itself?
Click Extensions > Apps Script to open the script editor, then copy the script text from the original spreadsheet and paste it into the script editor of another spreadsheet.
Calling a REST API in Google Sheets is as easy as installing the Apipheny app, then opening the app in your Google Sheet, entering your API request, and clicking “Run”. Keep reading for instructions on how to import REST API data into Google Sheets.
I had the same problem. The solution seems to be to create a custom menu that runs an Apps Script function instead of writing a custom function and invoking it from a cell in the spreadsheet.
A function that is triggered from a menu will ask the user for authorization if necessary and can consequently use all Apps Script services. I learned this here.
Example:
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('My Custom Menu')
.addItem('Run My Function', 'myFunction')
.addToUi();
}
function myFunction() {
SpreadsheetApp.getUi()
.alert('Running My Function');
}
After writing and saving this code:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With