@ez-gform/core

Read a Google Form's questions and submit answers to it, from any JavaScript. No dependencies. Works in Node 20+ and browsers.

Using React? You want @ez-gform/react instead.

Install

sh
pnpm add @ez-gform/core

Usage

ts
import { parseFormHtml, submitForm } from "@ez-gform/core";

// 1. Turn a public form's /viewform HTML into a typed schema.
const schema = parseFormHtml(html);

// 2. Submit answers, keyed by entry id.
const result = await submitForm(
  schema.formId,
  { "entry.123": "hello" },
  { schema },
);

result.status is "sent" by default: the request is no-cors (browsers require it), so you can't know whether Google accepted it. Outside the browser, pass mode: "cors" to get a real "ok" or "error".

What to pass for each kind of question is in the question types guide.

Other exports

ExportWhat it does
validateValues(values, schema)Finds unknown entry ids and missing required answers.
encodeValues(values, schema)Answers → URLSearchParams, without submitting.
buildSubmitBodyThe exact POST body submitForm sends.
buildPrefillUrlA link to the form prefilled with your values.
normalizeFormId, formUrlsAccept any form URL or id; get its endpoints.
parseFormData, extractPublicLoadDataLower-level parsing steps behind parseFormHtml.
ParseError, ValidationErrorError classes.