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. 1

    Define function doGet(e) in Code.gs. The parameter e carries query string parameters in e.parameter.

  2. 2

    Build output with HtmlService.createHtmlOutputFromFile, ContentService.createTextOutput, or JSON.stringify for APIs.

  3. 3

    Deploy with Deploy > New deployment, type Web app, and choose Execute as and Who has access.

  4. 4

    Share the deployment URL. Each new version needs a new deployment or version update to go live.

  5. 5

    Log e.parameter in test runs to confirm id and token query args arrive as expected.

  6. 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.

Build this without starting from a blank cell

Use a Better Sheets tool for doGet, then watch a walkthrough when you want the full pattern.

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

Browse more tutorials
Convert Google Sheets into a REST API

Convert Google Sheets into a REST API

How to use Google Sheets as a database by turning it into a REST API wit...
10 Google Sheets I Wish Someone Would Make

10 Google Sheets I Wish Someone Would Make

if you're looking for ideas on what sheets to make I think this video is...
Embed a Number in a Website from a Google Sheet

Embed a Number in a Website from a Google Sheet

Ever wanted to display some data from a google sheet on your site? Witho...
Add Click Tracking To Your Google Sheets | Bitly in a Google Sheet

Add Click Tracking To Your Google Sheets | Bitly in a Google Sheet

Create a click Edit: Google changed how the redirect is handled. It no l...
Create an Internal Google Sheets Add-on

Create an Internal Google Sheets Add-on

The entire process to create and publish a Google Sheets Add-on internal...
Curate Google Sheets Easily - Automatic Bookmarklet Maker

Curate Google Sheets Easily - Automatic Bookmarklet Maker

Curated sites, articles, and more web resources super easily into a Goog...

Related blog posts

Guides that explain doGet in more depth.

Browse the blog

Related glossary terms

Done reading about doGet?

Membership unlocks 636+ 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.