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.