Scriptdrill

Getting started Updated November 2026

PropertiesService

PropertiesService.getScriptProperties() is a small key value store attached to the script: setProperty("API_KEY", value) saves a string and getProperty("API_KEY") reads it back (null if missing). Values are always strings, so JSON.stringify objects. Use it for API keys, last-run timestamps and progress between trigger runs instead of hardcoding them.

Syntax

PropertiesService.getScriptProperties().setProperty(key, value) | .getProperty(key) | .deleteProperty(key)
PartWhat it is
getScriptProperties()Shared by everyone who runs the script; settings and keys
getUserProperties()Private to the current user of the script
getDocumentProperties()Tied to the bound spreadsheet or document
setProperties(object, deleteAll)Set several at once

Examples

const props = PropertiesService.getScriptProperties();
props.setProperty("API_KEY", "sk-live-...");
Logger.log(props.getProperty("API_KEY"));

Result: sk-live-... (the stored value)

Set keys once from a setup function or Project Settings, Script Properties, then delete the setup code.

const props = PropertiesService.getScriptProperties();
const last = Number(props.getProperty("LAST_ROW") || 1);
// process rows after last ...
props.setProperty("LAST_ROW", String(sheet.getLastRow()));

Result: Each run continues where the previous one stopped

const settings = {sheet: "Orders", threshold: 500, notify: ["ops@example.com"]};
props.setProperty("SETTINGS", JSON.stringify(settings));
const loaded = JSON.parse(props.getProperty("SETTINGS"));
Logger.log(loaded.threshold + 1);

Result: 501

Common mistakes

  • getProperty returns null: the key was never set, or it was set in User properties and read from Script properties; keep to one store.
  • The stored number comes back as a string and 1 + value gives 1201: properties are strings; wrap with Number().
  • Argument too large: values are limited to 9 KB each and 500 KB per store; keep big data in a sheet or Drive file.
  • API key still visible in the code: delete the setup line after running it once, or set the value in Project Settings instead of code.

Practice PropertiesService

These drills check your answer on live data, free, no account needed.

  • Merge settingsReturn a new object combining `base` and `override`. When both sides hold a plain object (made with `{}`) under the same key, merge those recursively. Anything else from `override` (arrays, dates, numbers, `null`) replaces what `base` had. Do not change either input.
  • Memoize`fn` takes one argument. Return a function that computes `fn(x)` only the first time it sees `x` and returns the stored result after that. Arguments are told apart the way a `Map` tells keys apart, so `1` and `"1"` are different. Results such as `0`, `false` and `undefined` are cached too. Each memoized function has its own cache.
  • Pick some keysReturn a new object with only the listed `keys` of `obj`. Skip keys that `obj` does not have, but keep keys it has even when the value is `0`, `false`, `null`, `""` or `undefined`. Do not change `obj`.

Questions

Are script properties secure?

Anyone with edit access to the script can read them, so they protect against accidental sharing of code, not against collaborators. Do not put keys in a shared sheet.

PropertiesService or CacheService?

Properties persist until you delete them; cache expires (up to 6 hours) and can be evicted early. Use properties for settings and state, cache for temporary API responses.

Related

  • UrlFetchAppCall APIs from Google Apps Script with UrlFetchApp.fetch: GET and POST requests, headers and bearer tokens, JSON payloads, muteHttpExceptions, to a sheet.
  • Time-driven triggersSchedule Google Apps Script with time-driven triggers: create them in the Triggers panel or with ScriptApp.newTrigger, run daily, hourly or weekly, delete.
  • JSON.parse and JSON.stringifyUse JSON.parse and JSON.stringify in Google Apps Script: turn an API response into objects, write nested fields to a sheet, store objects as properties.
  • Performance and batchingMake Google Apps Script faster: read and write in one getValues and setValues call, avoid getRange in loops, use flush and caching, beat the 6 minute limit.

Previous: Create calendar eventsNext: Logger.log and console.log