@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/coreUsage
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
| Export | What it does |
|---|---|
validateValues(values, schema) | Finds unknown entry ids and missing required answers. |
encodeValues(values, schema) | Answers → URLSearchParams, without submitting. |
buildSubmitBody | The exact POST body submitForm sends. |
buildPrefillUrl | A link to the form prefilled with your values. |
normalizeFormId, formUrls | Accept any form URL or id; get its endpoints. |
parseFormData, extractPublicLoadData | Lower-level parsing steps behind parseFormHtml. |
ParseError, ValidationError | Error classes. |