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

    Define function doPost(e) in Code.gs. Read the body with e.postData.contents and e.postData.type.

  2. 2

    Parse JSON with JSON.parse when clients send application/json.

  3. 3

    Validate required fields, sanitize values, and append or update rows with SpreadsheetApp.

  4. 4

    Deploy as a web app and give POST clients the same deployment URL used for GET.

  5. 5

    Return a text or JSON response so callers know success or failure.

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

Build this without starting from a blank cell

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

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

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 Email Form and Name Form into Website to Google Sheets

Embed Email Form and Name Form into Website to Google Sheets

Add names to the Email2Sheet apps script and code.
Send a Button from Google Sheets in an Email

Send a Button from Google Sheets in an Email

quick fun video to show you how to add a button to emails when you send ...
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...
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...

Related blog posts

Guides that explain doPost in more depth.

Browse the blog

Related glossary terms

Done reading about doPost?

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.