4

I am using the script editor in google spreadsheets, and I want to be able to make a simple HTTP request, but I keep getting the following error message:

Google Apps Script: You do not have permission to call fetch

I used the onEdit Function

function onEdit(e){
  var ui = SpreadsheetApp.getUi();
        var response = UrlFetchApp.fetch('http://www.google.com/');
    Logger.log(response.getContentText());
  } 

Why am I getting this error? Any help would be appreciated.

grizzthedj
  • 7,131
  • 16
  • 42
  • 62
Mr.Banks
  • 437
  • 2
  • 7
  • 19

1 Answers1

8

Simple triggers cannot use functionality that requires authorization Rename the function, then create an installed onEdit trigger for it. Call it manually within the Script Editor, proceed through the Authorization flow, and then the functionality will work as you expect.

Note that for things with quotas (such as UrlFetch), you may want to gate the call behind range checks, etc. (i.e. is event.range.getColumn() a desired value, etc).

tehhowch
  • 9,645
  • 4
  • 24
  • 42
  • i tried to create a function for the installable trigger but i get errors such as `You do not have permission to call getActive` while using `SpreadsheetApp.getActive();` would you be able to give a quick working example because once i fix one thing i get another error. :( – Mr.Banks Mar 06 '18 at 10:02
  • 2
    Did you run the function manually once within the script editor? That should trigger the authorization flow, in which you grant it permission. – tehhowch Mar 06 '18 at 12:54