Diagnostic reference
You do not have permission to call X
Why Google Apps Script blocks personal-data services, UrlFetchApp in onEdit, openById, or getUi across simple triggers, custom functions, and background runs.
Updated November 26, 2026
Apps Script error
Exception: You do not have permission to call GmailApp.sendEmail.
What it means
Simple triggers (onEdit and onOpen) and spreadsheet custom functions (=MYFUNC()) run without user authorization. Simple triggers cannot call services that require authorization, including GmailApp, MailApp, UrlFetchApp, DriveApp, CalendarApp, and SpreadsheetApp.openById(). Custom functions can call UrlFetchApp for public URLs, but they still cannot call personal-data services such as GmailApp, DriveApp, CalendarApp, or openById(). You also see this error when calling SpreadsheetApp.getUi() from a background trigger with no open spreadsheet window.
Related error messages
- Exception: You do not have permission to call UrlFetchApp.fetch.
- Exception: You do not have permission to call SpreadsheetApp.openById.
- Exception: You do not have permission to call SpreadsheetApp.getUi.
- Exception: Specified permissions are not sufficient to call ...
Before and after
The code before and after the fix.
// Simple triggers named onEdit cannot call GmailApp or UrlFetchApp.
function onEdit(e) {
if (!e || !e.range) return;
GmailApp.sendEmail('you@example.com', 'Sheet edited', e.range.getA1Notation());
}// Rename the function and install an "On edit" trigger under Triggers.
/** @param {Events.SheetsOnEdit} e */
function emailOnSheetEdit(e) {
if (!e || !e.range) return;
GmailApp.sendEmail('you@example.com', 'Sheet edited', e.range.getA1Notation());
}How to fix it
- If the error comes from onEdit() or onOpen(), rename the function (for example to emailOnSheetEdit). Then add an installable trigger in the Triggers sidebar.
- If the error comes from a cell formula (=MYFUNC()), move calls that need personal data (such as GmailApp, DriveApp, or openById) to a custom menu item or an installable trigger. Custom functions can still use UrlFetchApp for public URLs.
- If the error names SpreadsheetApp.getUi(), remove alerts or prompts from background triggers and log with Logger.log() instead.
- If appsscript.json lists explicit oauthScopes, add the missing scope URL and authorize the script again.
Things to check
- Rename the function away from onEdit or onOpen before installing a trigger. Otherwise Apps Script runs it twice, once unauthenticated and once through the installable trigger.
- If the file includes @OnlyCurrentDoc, SpreadsheetApp.openById() also fails on other files until you remove that comment.
In the Apps Script editor
Catch errors like this before clicking Run.
myFunction (published as Error Checker for Google Apps Script on the Chrome Web Store) checks your code while you edit at script.google.com. Diagnostics, autocomplete, and rule-based quick fixes are free without an account, run in your browser, and request no Google Drive, Gmail, or Apps Script project OAuth scopes.