Google Apps Script automation lets you turn a Google Sheet into a small database, a scheduled job or a webhook endpoint, using JavaScript that runs on Google’s servers. This guide maps the building blocks, the limits that shape every design, and the tutorial to read for each job.
Quick answer: This guide covers when a formula is enough, what Apps Script adds (triggers, HTTP calls, web apps), the quotas to design around, and which tutorial to open next. If you are new, read the formulas section first, then pick a tutorial from the list at the end.
- Try a formula first (QUERY, IMPORTRANGE, XLOOKUP) when the data already lives in Sheets.
- Open Extensions > Apps Script when you need to react to events, call an API or write data back.
- Add a trigger so the function runs on a schedule, on edit or on form submit.
- Check the limits before you build: 6 minutes per run, daily fetch quotas, overlapping runs.
- Follow the tutorial that matches your job.
In this guide
Before You Start
- Access: a Google account and edit access to the spreadsheet. The script editor lives under Extensions > Apps Script in the sheet’s menu.
- Authorization: the first time you run a function, Google asks you to approve the permissions it uses (Sheets, external requests, email). For your own script you may see “Google hasn’t verified this app”; click Advanced and continue to your project.
- Backups: scripts that write to a sheet can overwrite data. Make a copy of the file (File > Make a copy) before you test a new script on real data.
Start With Formulas, Reach for Script Second
Many jobs people write scripts for are a single formula. Formulas recalculate on their own and need no permissions:
- QUERY filters, groups and sorts a range using a SQL-like language. See the QUERY function guide.
- IMPORTRANGE pulls live data from another spreadsheet, which is how you build one master sheet from several source files.
- XLOOKUP replaces VLOOKUP and works in any direction (XLOOKUP vs VLOOKUP).
- REGEXEXTRACT and its siblings clean up messy text.
- Named functions wrap a long formula in a readable name you can reuse across the file.
Move to Apps Script when you need to react to events, call an external API, write data back, or run on a schedule.
What Apps Script Adds
- Triggers run a function on a schedule, on edit or on form submit. You add them from the clock icon (Triggers) in the editor’s left sidebar.
- UrlFetchApp calls any HTTP API, so a sheet can send webhooks to other apps or post rows to a chat channel.
- Web apps expose
doGetanddoPostfunctions as a URL, turning the spreadsheet into a simple JSON endpoint. The CRUD API tutorial builds one. - Custom functions let you call your own JavaScript from a cell, like
=MYFUNCTION(A2).
Limits to Design Around
These limits come from Google’s Apps Script quotas page. Check it before you depend on high volume, because Google can change the numbers.
- Runtime: a single execution is stopped after 6 minutes, on consumer and Workspace accounts alike. Process large jobs in batches and continue from a saved position, as the paginated API tutorial does.
- Cell-by-cell access is slow: read a whole range with
getValues(), work on the array in memory, and write it back once withsetValues(). - Overlapping runs: two executions can run at the same time. Anything that appends or updates rows should take a lock first; see preventing race conditions with LockService.
- Daily quotas: UrlFetchApp allows 20,000 calls a day on consumer accounts and 100,000 on Workspace. Email recipients are capped at 100 a day on consumer accounts and 1,500 on Workspace. Runs started by triggers share a daily total runtime of 90 minutes (consumer) or 6 hours (Workspace).
Example: A Webhook Receiver That Is Safe Under Concurrent Requests
This is the pattern most sheet integrations end up needing. Paste it into Code.gs in the Apps Script editor of a spreadsheet that has a tab named Leads. Then deploy it with Deploy > New deployment, choose Web app, set Execute as to Me and Who has access to Anyone, click Deploy and copy the web app URL. Apps Script answers POST requests with a redirect, so test with curl -L. The lock makes sure two requests arriving together do not write over each other.
function doPost(e) {
const lock = LockService.getScriptLock();
lock.waitLock(10000); // wait up to 10 seconds for other runs to finish
try {
const data = JSON.parse(e.postData.contents);
SpreadsheetApp.getActive()
.getSheetByName('Leads')
.appendRow([new Date(), data.name, data.email]);
return ContentService
.createTextOutput(JSON.stringify({ ok: true }))
.setMimeType(ContentService.MimeType.JSON);
} finally {
lock.releaseLock();
}
}If it worked, a POST with a JSON body such as {"name":"Test","email":"test@example.com"} adds a new row to Leads, and the response body is {"ok":true}. Each request also appears under Executions in the editor’s left sidebar.
A web app that is open to anyone has no built-in authentication. Add a shared secret to the request and check it at the top of doPost before you write anything.
When to Move Off Sheets
Sheets works well up to tens of thousands of rows with a handful of writers. Once you need many concurrent writes, strict data types, transactions or fine-grained access control, move the data to a real database and keep the sheet as a reporting view.
Common First-Run Problems
- The authorization prompt comes back after an edit: Google asks again whenever the script starts using a new service. Run the function once from the editor and approve the new permission.
- “Exceeded maximum execution time”: the run hit the 6-minute limit. Split the work into batches and save your position between runs.
- An error starting with “Service invoked too many times”: you used up a daily quota. Cut the number of calls (batch rows into one request) or wait for the quota to reset.
- The web app still runs old code: saving does not update a deployment. Open Deploy > Manage deployments, edit the deployment and select a new version.
- An on-edit trigger does not fire: edit triggers run only for changes a person makes in the sheet. Edits made by a script or the Sheets API do not fire them.
Frequently Asked Questions
Is Google Apps Script free?
Yes. Apps Script is included with every Google account at no extra cost. The trade-off is the quotas: consumer accounts get lower daily limits than Google Workspace accounts for URL fetches, email recipients and trigger runtime, so high-volume jobs may need a Workspace account or a different platform.
Is Apps Script the same as JavaScript?
It is JavaScript on Google’s V8 runtime, so modern syntax such as const, arrow functions and template literals works. It is not Node.js: there is no require, no npm packages and no file system. You reach Google services and the web through built-in services such as SpreadsheetApp and UrlFetchApp.
Should I use Apps Script or a tool like Zapier, Make or n8n?
Use Apps Script when the work centres on one spreadsheet and you are happy to write code. Use a workflow tool when you connect many apps, want a visual editor, or need runs longer than six minutes. The Zapier vs Make vs n8n comparison covers the trade-offs.
Can Apps Script run on a schedule without me opening the sheet?
Yes. A time-driven trigger runs the function on Google’s servers every minute, hour, day or week, even when the sheet is closed. Add it from the Triggers page in the editor, and check the Executions page if a scheduled run seems to be missing.
Tutorials in This Guide
- Google Sheets + ChatGPT: Bulk Content Creation WorkflowGenerate content in bulk with Google Sheets and ChatGPT: one keyword per row, one prompt template and an Apps Script that writes each result back.
- Google Sheets Dependent Dropdowns: Cascading MenusCreate dependent dropdowns in Google Sheets with FILTER or INDIRECT: sample data, per-row helper lists, 3-level cascades and fixes when the list is empty.
- Google Sheets Named Functions: Create Reusable FormulasCreate Google Sheets named functions step by step, reuse 10 copy-paste examples with sample results, import them into other files and fix common errors.
- Google Sheets QUERY Function: SQL Power Without SQLLearn the Google Sheets QUERY function on sample data: select, where, group by, pivot and dates, with exact results and fixes for #N/A, #REF! and #VALUE!.
- How to Fetch Paginated API Data in Google Apps ScriptFetch paginated API data in Google Apps Script: cursor and offset loops, batch writes with setValues, resume before the 6-minute limit, and 429 retries.
- How to Freeze Columns in Google Sheets: A Simple GuideFreeze columns in Google Sheets with the View menu, the drag bar or the mobile app, lock rows and columns together, and fix merged-cell errors.
- How to Perform CRUD Operations on Google Sheets with Apps ScriptTurn a Google Sheet into a CRUD API with Apps Script: one web app URL for create, read, update and delete, an API key check and curl tests.
- How to Send Facebook Leads to Google Sheets AutomaticallySend Facebook leads to Google Sheets automatically without coding: build a free Make scenario, map the fields, test with Meta's tool and fix Leads Access.
- How to Send Webhooks from Google Sheets with Apps ScriptSend webhooks from Google Sheets with Apps Script: post a row as JSON from an installable edit trigger, stop duplicate sends and add a secret header.
- ImportJSON for Google Sheets: Crypto and Stock PricesAdd an IMPORTJSON function to Google Sheets with Apps Script and pull crypto, stock and FX prices from APIs, with refresh options and error fixes.
- IMPORTRANGE in Google Sheets: Combine Files into a Master SheetUse IMPORTRANGE in Google Sheets to combine many files into one master sheet: worked example, QUERY filters, VSTACK, dedupe and #REF! fixes.
- Prevent Race Conditions in Google Apps Script WebhooksStop concurrent webhooks from overwriting rows in Google Sheets: add LockService to doPost, flush before release, and prove it with a 20-request test.
- REGEXEXTRACT in Google Sheets: Patterns to Clean Messy DataUse REGEXEXTRACT in Google Sheets to pull emails, phones, order IDs and URLs out of messy text, with sample results, RE2 rules and error fixes.
- Send Google Sheets Data to Discord: Apps Script TutorialPost Google Sheets rows to a Discord channel with an Apps Script webhook: create the webhook, run the script, add embeds, a trigger and retry handling.
- XLOOKUP vs VLOOKUP in Google Sheets: When and How to SwitchXLOOKUP vs VLOOKUP in Google Sheets, compared on sample data: why VLOOKUP breaks when columns move, how to convert formulas, and fixes for #N/A.
Next Steps
If you want to push sheet data to another service, start with the webhook-sending tutorial linked above. If you are receiving data, start with the LockService tutorial so concurrent requests cannot overwrite each other. For webhook security, retries and queues on the receiving side, read the API integrations and webhooks guide.

