# Legacy form authoring API

Create and edit form drafts by API, with an fa_ key scoped to one business. Publishing stays a human action.

> **Note:** For new integrations, start with [Website integration](/docs/agent-integration) and the [Integration API](/docs/integration-api). This reference covers existing fa_ credentials; they cannot register domains or read submissions.

## What an authoring key can do

A form authoring key (`fa_…`) creates and edits **drafts** in one business. It cannot publish a form, delete a form, or read or export leads. Publishing a draft is a human action taken in the dashboard, after review.

A new key defaults to **create** scope: it can create forms, and afterward read or edit only the forms that same key created. Choose **forms** scope instead to read and edit a specific list of existing form IDs, without the ability to create. Expiry is 1 to 72 hours, 24 by default. Whoever issues the key must keep forms edit permission for the key to keep working.

> **Warning:** An `fa_` key is a local development credential, not a production secret. Put it in a gitignored `.inflow.env` at the repo root and source it per command. Do not put it in `.env`, or `.env.local` — framework env files get loaded into builds and the key can end up in the client bundle. Never commit it, never set it as a deployed environment variable, and never put it in a URL. The `pk_` public key is the one that ships in browser code; the `fa_` key never leaves your machine.

Create a key from a form editor's **Settings**. The secret is shown once. Older unscoped keys are blocked from authoring operations; revoke and reissue them.

## Endpoints

Base URL is `https://api.inflow.build`. Every request sends `Authorization: Bearer $INFLOW_FORM_AUTHORING_KEY`. The global body limit is 1 MiB, and responses carrying keys or definitions send `Cache-Control: no-store`.

| Endpoint | What it does |
| --- | --- |
| GET /api/form-authoring/catalog | Live JSON Schema, endpoint list, and valid field types and variants. Fetch this before writing a form — it is canonical. |
| POST /api/form-authoring/validate-definition | Checks a document and returns field-level issues without writing anything. |
| GET /api/form-authoring/forms | Lists only the forms this key may read. |
| POST /api/form-authoring/forms | Creates a new draft. Create-scope keys only. The new form stays unpublished. |
| GET /api/form-authoring/forms/:id | Returns an allowed form's effective draft definition and its current revision. |
| PUT /api/form-authoring/forms/:id | Writes an edited draft. Requires expectedRevision from the latest GET. |

Forms are a portable document: `{"format":"inflow-form","version":1,"definition":{...}}`. Keep it in a file and reuse that file for validation and creation, so what you validate is what you send.

```sh
source .inflow.env

curl -sS -H "Authorization: Bearer $INFLOW_FORM_AUTHORING_KEY" \
  "$INFLOW_API_BASE/api/form-authoring/catalog"

curl -sS -X POST "$INFLOW_API_BASE/api/form-authoring/validate-definition" \
  -H "Authorization: Bearer $INFLOW_FORM_AUTHORING_KEY" \
  -H "Content-Type: application/json" \
  --data-binary @form.json

curl -sS -X POST "$INFLOW_API_BASE/api/form-authoring/forms" \
  -H "Authorization: Bearer $INFLOW_FORM_AUTHORING_KEY" \
  -H "Content-Type: application/json" \
  --data-binary @form.json
```

## Editing a draft

Editing is read, modify, write, with a revision check. GET the form to get its current `definition` and `revision`. Edit the definition. Add `expectedRevision` set to that revision at the top level of the document. PUT it back.

> **Note:** A stale revision returns HTTP 409 with `currentRevision`. Re-GET the form, reapply your change onto the newer draft, and retry. Never retry by bumping the number to match — that silently overwrites a human's edit made in the dashboard.

> **Warning:** Preserve the ID of every step, nested field, and option you are not deliberately replacing. Collected answers are keyed to these IDs. Changing one orphans the data already tied to it.

## Mapping answers to a lead

Set `mapping` on an answer step, or on a field inside a composite step, to send that answer to a specific place on the lead rather than leaving it in the response list. Targets: `contact.name`, `contact.email`, `contact.phone`, `notes`, `field` (with a stable lowercase key, for example `{"target":"field","key":"project_budget"}`), and `none`.

Each destination may be used only once per form, including across conditional branches. Without an explicit mapping, the destination is inferred from the question's label, which breaks the first time someone rewords that label. Set it explicitly on anything you want to land in the CRM. `none` keeps the answer in form responses without copying it anywhere.

> **Warning:** Once the form is published and installed with the `pk_` key, the site's production, preview, and localhost origins must be registered in inFlow under **Environments**. A submission from an origin that isn't registered is rejected. This is the most common reason a correctly built form returns a 403 once it's live.

## Components that don't render

> **Warning:** The schema accepts these, so validation passes and the visitor still hits a broken form. File upload: The widget has no branch for it and renders "Unsupported step type." Address and ranking inside a composite step: They fall back to a plain text box and store the wrong answer shape. Appointment or calendar inside a composite step: Plain date input only, with no availability logic. A top-level calendar step works once the business has configured availability. Do not build a form using them.
