What is doPost in Google Sheets Apps Script?
doPost is the Apps Script handler for HTTP POST requests to your web app URL. External forms, Zapier, or custom clients send data in the request body, and doPost parses it and writes to your spreadsheet. Pair it with doGet when you need both a landing page and a submit endpoint.
When to use it
Use doPost when data arrives from a submit action: web form POST, webhook from another tool, mobile app callback, or API client adding rows without opening the sheet.
When to skip it
Skip doPost for read-only lookups; use doGet instead. Do not expose an open POST endpoint without validation if Anyone can access the deployment.
How it works
-
1
Define function doPost(e) in Code.gs. Read the body with e.postData.contents and e.postData.type.
-
2
Parse JSON with JSON.parse when clients send application/json.
-
3
Validate required fields, sanitize values, and append or update rows with SpreadsheetApp.
-
4
Deploy as a web app and give POST clients the same deployment URL used for GET.
-
5
Return a text or JSON response so callers know success or failure.
-
6
Log failures to a Debug tab or Executions for support when integrations break.
Examples in Google Sheets
Webhook intake
doPost parses JSON from a CRM webhook and appends name, email, and source columns to a Leads sheet.
HTML form submit
A public form posts application/x-www-form-urlencoded data. doPost maps e.parameter fields to columns and returns Thank you text.
Internal API create row
Authenticated POST with a shared token in the header appends a row only when the token matches Script Properties.
Better Sheets resources
Common mistakes
-
Accepting any POST without checking a secret token or allowlist, letting strangers fill your sheet.
-
Assuming e.parameter works for all JSON bodies; raw JSON often needs JSON.parse on e.postData.contents.
-
Not returning HTTP-friendly error messages, making Zapier or Make retries hard to diagnose.
-
Writing duplicate rows on webhook retries instead of checking for an existing external ID.
-
Deploying with Execute as Me while expecting each poster's personal sheet access.
Frequently asked questions
- What is the difference between doGet and doPost?
- doGet handles browser GET requests and links. doPost handles POST bodies from forms and API clients sending data.
- How do I parse JSON in doPost?
- Use JSON.parse(e.postData.contents) when Content-Type is application/json. Handle parse errors in try/catch.
- Can Zapier call doPost?
- Yes. Point a Webhooks step at your web app URL with POST and match the body format your script expects.
- Does doPost need CORS headers?
- Browser calls from other domains may need special handling. Server-to-server POSTs often work without CORS.
- How do I secure doPost?
- Use a shared secret in headers, restrict Who has access, validate input, and avoid returning sensitive data in responses.
- Why is my POST body empty?
- Check postData.type, whether the client sends JSON or form encoded data, and log e.postData.contents in Executions.
- Can doPost send email after insert?
- Yes. After appendRow, call MailApp if the deployment account authorized mail scopes.
- Do I need a new deployment for doPost?
- doGet and doPost live in the same web app deployment. One URL routes by HTTP method.
Related Tutorials
Watch how doPost works
Convert Google Sheets into a REST API
10 Google Sheets I Wish Someone Would Make
Embed Email Form and Name Form into Website to Google Sheets
Send a Button from Google Sheets in an Email
Add Click Tracking To Your Google Sheets | Bitly in a Google Sheet
Embed a Number in a Website from a Google Sheet
Related blog posts
Guides that explain doPost 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 →Explore Coding in Google Sheets
Did you know you can actually code in Google Sheets?
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 →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 →Google Sheets workflows
A workflow is the path work takes through your sheet: intake, review, approval, done. Good workflows use consistent columns, statuses everyone understands, and just enough automation to move tasks forward without hiding steps from the team.
Read guide →Done reading about doPost?
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.