Keep settings and secrets out of the code
Apps Script recipes › APIs, cache and settings
Script Properties hold API keys and settings; a setup function asks for them once.
File Code.gs
function setting_(name, fallback) {
const value = PropertiesService.getScriptProperties().getProperty(name);
return value === null ? fallback : value;
}
/** Run once from the editor, then delete the key from this code. */
function saveApiKey() {
PropertiesService.getScriptProperties().setProperty('API_KEY', 'paste-the-key-here');
}
Good to know
- Script Properties are shared by everyone who runs the script; User Properties are per person.
- Anyone who can edit the script can read its properties: they hide secrets from the code, not from editors.
Let the AI put it in your appGAS AI Builder knows every recipe here. Describe your app and it uses this code where it fits, in a Google Apps Script project in your own Drive.
Use it in a project