What is doGet in Google Sheets Apps Script?
doGet is a special function Apps Script calls when someone opens your web app URL with a browser GET request. It can return an HTML page from HtmlService, plain text, or JSON from ContentService. It is the front door for read-only views, lookup tools, and simple APIs backed by your sheet.
When to use it
Use doGet when visitors need to load a page or fetch data with a link: status lookup by ID, embedded report, JSON feed of rows, or a form that loads before a doPost submit.
When to skip it
Skip doGet for actions that change data via a bookmarkable link alone; prefer POST with doPost or server functions with validation so accidental clicks do not write rows.
How it works
-
1
Define function doGet(e) in Code.gs. The parameter e carries query string parameters in e.parameter.
-
2
Build output with HtmlService.createHtmlOutputFromFile, ContentService.createTextOutput, or JSON.stringify for APIs.
-
3
Deploy with Deploy > New deployment, type Web app, and choose Execute as and Who has access.
-
4
Share the deployment URL. Each new version needs a new deployment or version update to go live.
-
5
Log e.parameter in test runs to confirm id and token query args arrive as expected.
-
6
Set MIME type explicitly for JSON and set headers if consumers expect application/json.
Examples in Google Sheets
Row lookup by ID
doGet reads e.parameter.id, finds the row on the Orders tab, and returns an HTML table of status and ship date.
JSON export
doGet returns ContentService.createTextOutput(JSON.stringify(rows)).setMimeType(ContentService.MimeType.JSON) for a dashboard to consume.
Landing page with form
doGet serves Form.html. The form submits via google.script.run or posts to doPost for the actual write.
Better Sheets resources
Common mistakes
-
Exposing sensitive rows when Who has access is Anyone and Execute as Me without filtering by user.
-
Returning huge unfiltered datasets that slow the web app and leak more data than needed.
-
Forgetting to redeploy after code changes, then wondering why old HTML still appears.
-
Using doGet to delete or approve records from a single clickable URL with no confirmation.
-
Not handling missing e.parameter keys, causing errors on bare URL visits.
Frequently asked questions
- What is the e parameter in doGet?
- e.parameter is an object of query string keys and values from the URL, such as ?id=42 becomes e.parameter.id.
- Can doGet write to the sheet?
- Technically yes, but GET should be safe and idempotent. Use doPost or validated server calls for writes.
- How do I test doGet locally?
- Run doGet from the editor with a mock event object, or deploy as test and open the URL with sample query params.
- Why does doGet ask me to authorize?
- Execute as User accessing the app requires each visitor to grant scopes. Execute as Me runs as the deployer with their permissions.
- Can I return HTML and JSON from the same project?
- Yes. Branch inside doGet on a query param like format=json, or use separate deployments.
- Does doGet run when the sheet is closed?
- Yes. Web app requests run in the cloud without the spreadsheet UI open.
- What is the difference between doGet and google.script.run?
- doGet serves HTTP visitors at a public or restricted URL. google.script.run calls server code from HtmlService inside an open spreadsheet session.
- How do I cache expensive doGet reads?
- Use CacheService to store JSON for a few minutes so repeated lookups do not reread the whole sheet every time.
Related Tutorials
Watch how doGet works
Convert Google Sheets into a REST API
10 Google Sheets I Wish Someone Would Make
Embed a Number in a Website from a Google Sheet
Add Click Tracking To Your Google Sheets | Bitly in a Google Sheet
Create an Internal Google Sheets Add-on
Curate Google Sheets Easily - Automatic Bookmarklet Maker
Related blog posts
Guides that explain doGet in more depth.
How to Use Google Sheets as a Website Database
Did you know you can use Google Apps Script to turn a Google Sheet into a free, auto-syncing database for your website? This guide shows you exactly how to set it up. You’ll prepare your spreadsheet, write a few lines of code and publish your site. Don’t worry if you’re not a developer, we’ll walk you through it. Why Use Google Sheets as a Database? For small projects, Google Sheets offers many advantages over traditional databases: * Free hosting and storage * Easy to edit data without...
Read post →What's Better Than Google Sheets?
Nothing is better than Google Sheets. You just need to learn more about the unlimited power of Google Sheets. Functions, Formulas, Apps Script and more.
Read post →When did you learn the secrets of Google Sheets? | Sheet Talking Episode 8 Esa
Esa is a beginner at Google Sheets. I discover the moment he discovered the deepest secrets of Google Sheets. And we wax poetic about AI in sheets, and data flow.
Read post →Related terms
Apps Script web apps
A web app turns your script into a URL that runs doGet or doPost when someone visits or posts data. The page can read and write your spreadsheet behind the scenes, which is useful for simple forms, internal tools, and lightweight APIs without standing up a separate server.
Read guide →Google Sheets API
The Google Sheets API lets other programs read and update spreadsheets over HTTP using JSON. It is how dashboards, backends, and mobile apps sync data without opening the Google Sheets UI. Apps Script inside a file is simpler for sheet owners; the API fits systems built in Python, Node, or other stacks.
Read guide →Script Editor
The Script Editor is the Apps Script workspace inside your spreadsheet where you write JavaScript that talks to Sheets, Gmail, and other Google services. You open it from Extensions > Apps Script. Every function you save can be run manually, bound to a trigger, or linked from a custom menu.
Read guide →Google Sheets automation
Automation means work happens without repeating the same clicks every day: imports update, emails send, rows move, and dashboards refresh. In Sheets, automation usually stacks built-in features, Apps Script, and sometimes the Sheets API or add-ons. Start with the lightest tool that still solves the job.
Read guide →Done reading about doGet?
Membership unlocks 600+ tutorials, unlimited generators, and every template. Practical lessons. Zero fluff.
Need this once
Jump to a free tool or a single tutorial for this topic.
Learning Sheets for real
Unlock the full library, generators, and templates with membership.