Basker Docs

Forms

Read a form definition with the FrontStage API and submit entries to the form endpoint of the site

The FrontStage API reads form definitions. It does not take submissions. To send an entry, POST it to the submitUrl of the form on the Basker site.

Get the form definition

query ContactForm($id: ID!) {
  form(id: $id) {
    id
    title
    submitUrl
    submitButtonLabel
    confirmationType
    confirmationMessage { html }
    redirectUrl
    fields {
      name
      type
      label
      required
      width
      defaultValue
      options
    }
  }
}
{
  "data": {
    "form": {
      "id": "6afccde2f389348df01dbf33",
      "title": "Get in touch",
      "submitUrl": "https://www.example.org/forms/6afccde2f389348df01dbf33/submit",
      "submitButtonLabel": "Send",
      "confirmationType": "message",
      "confirmationMessage": { "html": "<p>Thanks, we will be in touch.</p>" },
      "redirectUrl": null,
      "fields": [
        { "name": "name", "type": "text", "label": "Name", "required": true, "width": null, "defaultValue": null, "options": null },
        { "name": "email", "type": "email", "label": "Email", "required": true, "width": null, "defaultValue": null, "options": null },
        { "name": "message", "type": "textarea", "label": "Message", "required": false, "width": null, "defaultValue": null, "options": null }
      ]
    }
  }
}

You get the form ID from the block or field that shows the form. On a website builder site, the website-main-form block has the full definition in resolved.form. To list every form of the site, use forms:

{
  forms {
    id
    title
    submitUrl
  }
}
FormField fieldDescription
nameThe key to send for this input.
typeThe input type, for example text, email, textarea, select, or checkbox.
label, required, width, defaultValueThe settings the editor chose.
optionsThe choices for select, radio, and checkbox group inputs.
settingsEvery stored setting of the input, as JSON.

Submit an entry

Send a POST request to submitUrl, the absolute URL of the submit endpoint. Send JSON with one key for each field name:

curl -s -X POST https://www.example.org/forms/6afccde2f389348df01dbf33/submit \
  -H 'Content-Type: application/json' \
  -d '{"name":"Ada","email":"ada@example.org","message":"Hello"}'
{
  "success": true,
  "message": "Thanks, we will be in touch.",
  "message_html": "Thanks, we will be in touch.",
  "form_submitted": "contact"
}
ResultResponse
Confirmation message200 with success, message, message_html, and form_submitted.
Redirect after submit200 with success and redirect: the URL to send the visitor to.
A required field is empty or a value is not valid400 with { "error": "Validation failed", "errors": { "<field name>": "<message>" } }.
The form does not exist404 with { "error": "Form not found" }.
Too many fields, or a body larger than 64 KB400 or 413.

The endpoint also accepts application/x-www-form-urlencoded and multipart/form-data. For those content types it answers with a redirect, not JSON.

Submit from your server

The submit endpoint does not accept browser requests from other domains. Send the entry from your own server, for example from an Astro endpoint or a Next.js route handler, and return the result to the browser:

app/api/contact/route.ts
export async function POST(request: Request) {
  const entry = await request.json();
  const response = await fetch("https://www.example.org/forms/6afccde2f389348df01dbf33/submit", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(entry),
  });
  return new Response(await response.text(), {
    status: response.status,
    headers: { "Content-Type": "application/json" },
  });
}

Spam protection

When the site turns on reCAPTCHA in the Google app, every submission needs a reCAPTCHA v3 token in the recaptchaToken key. Without a token, the endpoint returns 400 with { "error": "Security verification required" }. Get the token in the browser with the site key, and send it with the entry. On a website builder site, resolved.recaptchaSiteKey of the form block holds the site key.

On this page