I am sending http request from script editor in google spreadsheets, but I keep getting the following error message:
`Google Apps Script: You do not have permission to call UrlFetchApp.fetch. Required permissions: https://www.googleapis.com/auth/script.external_request`
I am using onEdit function:
function onEdit(e){
var ui = SpreadsheetApp.getUi();
var response = UrlFetchApp.fetch('http://www.eur-api.idomoo.com/');
Logger.log(response.getContentText());
}
I don't know Why am I getting this error? and I also gave permission to script.external_request scope, Any help would be appreciated.
UrlFetchApp. Fetch resources and communicate with other hosts over the Internet. This service allows scripts to communicate with other applications or access other resources on the web by fetching URLs. A script can use the URL Fetch service to issue HTTP and HTTPS requests and receive responses.
UrlFetchApp methods are synchronous. They return an HttpResponse object, and they do not take a callback.
onEdit is invoked by a Simple Trigger when a user changes a value in a spreadsheet.
However, simple triggers cannot access services that require authorization, such as UrlFetchApp.fetch
. See the Google Apps Script guide
What you can do is to simply rename the function onEdit to something else, such as atEdit, so as to remove the simple trigger. Then follow the Current project's triggers
menu...
and add a trigger to be called in the event of On edit
.
And when creating the trigger, you will follow the Wizard to grant your apps script permission to connect to an external service.
I know its an old thread, but I find it weird of having to rename the method to something else, e.g. from onEdit to onEditHandler just to make it work. It turns out that I can make it work by:
This is possible probably due to previously the handler doesn't have the fetch url, therefore it doesn't have to ask for authorization to access external request. Once it is re-added, then it has the proper authorization because you are asked to re-authorize the handler.
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