Skip to content
Join our Slack

TypeScript SDK

@fomr/sdk is the official TypeScript client for the Platform API. It gives you a Fomr client with typed resource methods, lazy cursor pagination, typed errors, and built-in retries.

The package is ESM-only, needs Node.js 26.12.1 or newer, and has no runtime dependencies. Use it in servers, scripts, and command-line tools, never in browser code: a Personal Access Token must stay on the server.

Terminal window
pnpm add @fomr/sdk

Set a Personal Access Token in your environment:

Terminal window
read -rs FOMR_TOKEN
export FOMR_TOKEN

Create tokens under Settings > API; see Authentication. The SDK reads FOMR_TOKEN when you omit the token option.

import { Fomr, PublishValidationError } from '@fomr/sdk';
const fomr = new Fomr({ token: process.env.FOMR_TOKEN });
const form = await fomr.forms.create({
name: 'Event registration',
pages: [
{
name: 'Welcome',
type: 'intro',
nodes: [
{ sort_order: 1, type: 'text', meta: { content: '<p>Join us for the Acme Events community meetup.</p>' } },
{ sort_order: 2, type: 'actions', meta: { label: 'Start' } },
],
},
{
name: 'Your details',
type: 'normal',
nodes: [
{
sort_order: 1,
type: 'text_input_short',
meta: { question: '<span>Full name</span>', placeholder: 'Jane Doe', validation: { required: true } },
},
{
sort_order: 2,
type: 'text_input_email',
meta: { question: '<span>Email address</span>', placeholder: '[email protected]', validation: { required: true } },
},
{ sort_order: 3, type: 'actions', meta: { label: 'Register' } },
],
},
{
name: 'Thank you',
type: 'final',
nodes: [{ sort_order: 1, type: 'thank_you', meta: { thank_you_title: '<h1>See you there!</h1>' } }],
},
],
});
const check = await fomr.forms.validate(form.public_id);
if (!check.valid) {
process.stderr.write(`${JSON.stringify(check.issues)}\n`);
}
try {
const published = await fomr.forms.publish(form.public_id);
process.stdout.write(`${published.urls.share}\n`);
} catch (error) {
if (error instanceof PublishValidationError) {
const issues = error.issues.map((issue) => `${issue.code}${issue.path.length ? ` at ${issue.path.join('.')}` : ''}`);
process.stderr.write(`${issues.join('\n')}\n`);
} else {
throw error;
}
}
for await (const submission of await fomr.submissions.list(form.public_id, { status: 'completed' })) {
process.stdout.write(`${submission.public_id}: ${JSON.stringify(submission.answers)}\n`);
}

Each Fomr instance has its own token and settings. Create separate clients when two jobs need different tokens or API origins.

new Fomr(options) accepts these options:

OptionTypeDefaultWhat it controls
tokenstring | () => string | Promise<string>FOMR_TOKENThe Personal Access Token. A function runs before every attempt, so you can rotate tokens.
baseUrlstringhttps://platform.fomr.ioThe Platform API origin, for example a local test server. It must use https://; http:// is allowed only for localhost, 127.0.0.1, and [::1]. Any other origin throws FomrConfigurationError.
fetchtypeof globalThis.fetchglobalThis.fetchA Fetch implementation, for tests or custom networking. Treat it as trusted code.
headersHeadersInitNoneHeaders added to every request. The SDK always sets its own Authorization and User-Agent.
userAgentstringNoneYour product identifier, placed before fomr-sdk/<version>.
timeoutMsnumber30000Request timeout in milliseconds.
maxRetriesnumber2Automatic retries after the first attempt.
maxRetryDelayMsnumber60000The longest wait the SDK accepts before a retry.

A token function returns only the token value:

const fomr = new Fomr({
token: async () => process.env.FOMR_TOKEN ?? '',
userAgent: 'registration-sync/2.1.0',
});

Every method accepts a final options object for that one call:

  • signal, headers, timeoutMs, and maxRetries.
  • dryRun: true on forms.create(), templates.create(), forms.updateDraft(), workflows.create(), and workflows.replace(). The server validates and resolves the document without storing anything.
  • workspace_public_id on forms.create() and templates.create(), to create outside the Default Workspace.

The client groups resource operations under forms, templates, workspaces, workflows, themes, domains, integrationConnections, and submissions. Public IDs are positional arguments, while request and response fields keep the API’s snake_case names.

fomr.forms covers form creation, reads, drafts, lifecycle changes, conversion to a Private Template, and duplication:

const form = await fomr.forms.get('Ev3ntReg01');
const draft = await fomr.forms.getDraft(form.public_id);
draft.blueprint.name = 'Autumn event registration';
const updated = await fomr.forms.updateDraft(form.public_id, draft.blueprint);
const validation = await fomr.forms.validate(form.public_id);
if (validation.valid) {
await fomr.forms.publish(form.public_id);
}
process.stdout.write(`${updated.etag}\n`);

Draft reads and writes return { blueprint, etag }; a dry-run write has an etag of null. forms.create(), forms.duplicate(), and templates.createForm() return the form resource plus the stored draft and its etag, so you can edit the new draft without reading it again.

A dry-run create stores nothing. It returns { dry_run: true, draft, etag: null }, where draft is what the real call would store. Its IDs are not reserved:

const preview = await fomr.forms.create(blueprint, { dryRun: true });
const created = await fomr.forms.create(blueprint);
await fomr.forms.updateDraft(created.public_id, { ...created.draft, name: 'Spring event registration' });

CanonicalBlueprint, the read type, is assignable to FormBlueprint, the write type, so you can read, edit, and write back a draft without rebuilding it or losing unknown fields. See Forms for draft behavior.

forms.updateAccess() also takes duplicate_response_rule, and forms.setDomain() and forms.removeDomain() bind the share link to a custom domain:

await fomr.forms.updateAccess('Ev3ntReg01', { duplicate_response_rule: { type: 'component', node_public_id: 'nEml' } });
const domains = await fomr.domains.list();
const form = await fomr.forms.setDomain('Ev3ntReg01', { domain: 'forms.acme.com', slug: '/register' });
process.stdout.write(`${domains.length} domains, ${form.domain?.host}\n`);

fomr.themes.list() returns the system themes and your organization’s themes, and fomr.themes.get(themeId) reads one. is_system marks a theme of the fomr catalog, and is_new_form_default the theme a new form receives. Apply a theme by sending its ID as styles.theme_id in a draft write, and change one form’s design with styles.override_properties; theme_name is read-only. fomr.themes.searchUnsplashPhotos({ query }) finds Unsplash photos, and fomr.forms.setBackgroundImage(formId, photoId) sets one as the background and credits the photographer. See Themes:

const themes = await fomr.themes.list();
const theme = themes.find((candidate) => !candidate.is_system) ?? themes[0];
const draft = await fomr.forms.getDraft('Ev3ntReg01');
await fomr.forms.updateDraft('Ev3ntReg01', { ...draft.blueprint, styles: { theme_id: theme.id } });

fomr.templates provides focused methods for Private Templates:

const templateBlueprint = (await fomr.forms.getDraft('Ev3ntReg01')).blueprint;
const templates = await fomr.templates.list({ limit: 25 });
const template = await fomr.templates.create(templateBlueprint);
const form = await fomr.templates.createForm(template.public_id, {
name: 'Customer onboarding',
});

templates.list() returns only Private Templates, templates.create() creates one, and templates.createForm() copies a template into a new form. A template is never published: forms.publish(), forms.unpublish(), and forms.validate() reject one with 400 INVALID_INPUT at is_template.

fomr.workspaces.list() returns every workspace, the Default Workspace first. Use a workspace ID to filter forms.list(), create in a workspace, or move a form:

const workspaces = await fomr.workspaces.list();
const events = workspaces.find((workspace) => workspace.name === 'Events');
if (events) {
const eventForms = await fomr.forms.list({ workspace_public_id: events.public_id });
const created = await fomr.forms.create(blueprint, { workspace_public_id: events.public_id });
await fomr.forms.move('Ev3ntReg01', events.public_id);
}

forms.move() needs the Pro workspaces feature and throws PlanError on Free. forms.delete() moves a form to Trash, and forms.restore() brings it back as a draft within 30 days.

workspaces.create(), get(), and update() manage the workspaces themselves, with the app’s rules described in Workspaces:

const research = await fomr.workspaces.create({ name: 'Customer research', color: 'teal' });
await fomr.workspaces.update(research.public_id, { name: 'Research', position: 0 });

workspaces.create() needs the Pro workspaces feature. Deleting a workspace is done in the app only.

fomr.workflows reads and writes a form’s workflows as whole Workflow Documents. create() and replace() accept { dryRun: true }, which resolves to { dry_run: true, workflow } and writes nothing. Pick a connection_public_id from fomr.integrationConnections.list(). See Workflows:

const connections = await fomr.integrationConnections.list();
const connection = connections.find((candidate) => candidate.status === 'connected');
if (connection) {
const workflow = await fomr.workflows.create('Ev3ntReg01', {
name: 'Send responses to Google Sheets',
nodes: [
{ public_id: 'trigger-new-response', node_type_key: 'form_completed', position: { x: 0, y: 0 } },
{
public_id: 'sheet-leads',
node_type_key: 'google_sheets_add_row',
position: { x: 360, y: 0 },
config: { connection_public_id: connection.public_id, spreadsheet_name: 'Event registrations' },
},
],
edges: [{ source_node_public_id: 'trigger-new-response', target_node_public_id: 'sheet-leads' }],
});
await fomr.workflows.enable('Ev3ntReg01', workflow.public_id);
}

A connection’s display_name is null when the provider reported no account name. A Workflow read result is assignable to WorkflowWriteInput, so workflows.get() output can go back to workflows.replace() after editing. workflows.list() returns the workflows without their graphs, and disable() and delete() turn a workflow off or remove it.

List and read submissions through fomr.submissions. export() returns a native Response, so you can stream the file without holding it in memory:

import { createWriteStream } from 'node:fs';
import { Writable } from 'node:stream';
const submissions = await fomr.submissions.list('Ev3ntReg01', {
limit: 100,
status: 'completed',
});
const submission = await fomr.submissions.get('Ev3ntReg01', 'Sb01EventReg2026Ab3cDe');
const exportResponse = await fomr.submissions.export('Ev3ntReg01', { format: 'jsonl' });
const exportFile = Writable.toWeb(createWriteStream('submissions.jsonl'));
await exportResponse.body?.pipeTo(exportFile);
process.stdout.write(submission.public_id);

Identity and usage operations sit directly on the client:

const identity = await fomr.me();
const usage = await fomr.usage();
process.stdout.write(`${identity.organization.name}: ${usage.plan}\n`);

fomr.revokeCurrentToken() permanently revokes the token the client is using. Every later call with that token fails.

fomr.request() calls an endpoint your installed SDK version does not cover yet. It uses the same authentication, timeouts, error mapping, and rate-limit parsing:

const response = await fomr.request<{ enabled: boolean }>('GET', '/v1/future-capability', {
query: { form_public_id: 'Ev3ntReg01' },
});
process.stdout.write(String(response.data.enabled));

Prefer a resource method when one exists; it has typed inputs and results and operation-specific retry rules. request() decides retries from the HTTP method alone: GET, HEAD, and PUT are retried, while POST, PATCH, and DELETE are never retried after a connection failure or 5xx.

request() accepts only relative paths under /v1 on the configured origin. The SDK never follows redirects, so your token is never sent to another location.

Every Platform API operation and its SDK method:

HTTP operationSDK callResult
GET /v1/mefomr.me()Me
DELETE /v1/me/tokenfomr.revokeCurrentToken()RevokedToken
GET /v1/usagefomr.usage()Usage
GET /v1/formsfomr.forms.list(query) or fomr.templates.list(query)Page<Form>
POST /v1/formsfomr.forms.create(blueprint) or fomr.templates.create(blueprint)CreatedForm
GET /v1/forms/{form_public_id}fomr.forms.get(formPublicId)Form
DELETE /v1/forms/{form_public_id}fomr.forms.delete(formPublicId)void
POST /v1/forms/{form_public_id}/restorefomr.forms.restore(formPublicId)Form
POST /v1/forms/{form_public_id}/movefomr.forms.move(formPublicId, workspacePublicId)Form
GET /v1/forms/{form_public_id}/draftfomr.forms.getDraft(formPublicId)DraftDocument
PUT /v1/forms/{form_public_id}/draftfomr.forms.updateDraft(formPublicId, blueprint)DraftWriteResult
GET /v1/forms/{form_public_id}/publishedfomr.forms.getPublished(formPublicId)CanonicalBlueprint
POST /v1/forms/{form_public_id}/validatefomr.forms.validate(formPublicId)FormValidationResult
POST /v1/forms/{form_public_id}/publishfomr.forms.publish(formPublicId)Form
POST /v1/forms/{form_public_id}/unpublishfomr.forms.unpublish(formPublicId)Form
POST /v1/forms/{form_public_id}/closefomr.forms.close(formPublicId)Form
POST /v1/forms/{form_public_id}/reopenfomr.forms.reopen(formPublicId)Form
PATCH /v1/forms/{form_public_id}/accessfomr.forms.updateAccess(formPublicId, input)Form
POST /v1/forms/{form_public_id}/duplicatefomr.forms.duplicate(formPublicId, input) or fomr.templates.createForm(templatePublicId, input)CreatedForm
POST /v1/forms/{form_public_id}/mark-templatefomr.forms.markTemplate(formPublicId)Form
PUT /v1/forms/{form_public_id}/domainfomr.forms.setDomain(formPublicId, input)Form
DELETE /v1/forms/{form_public_id}/domainfomr.forms.removeDomain(formPublicId)Form
GET /v1/workspacesfomr.workspaces.list()Workspace[]
POST /v1/workspacesfomr.workspaces.create(input)Workspace
GET /v1/workspaces/{workspace_public_id}fomr.workspaces.get(workspacePublicId)Workspace
PATCH /v1/workspaces/{workspace_public_id}fomr.workspaces.update(workspacePublicId, input)Workspace
GET /v1/themesfomr.themes.list()Theme[]
GET /v1/themes/{theme_id}fomr.themes.get(themeId)Theme
GET /v1/domainsfomr.domains.list()Domain[]
GET /v1/forms/{form_public_id}/workflowsfomr.workflows.list(formPublicId)WorkflowSummary[]
POST /v1/forms/{form_public_id}/workflowsfomr.workflows.create(formPublicId, document)Workflow
GET /v1/forms/{form_public_id}/workflows/{workflow_public_id}fomr.workflows.get(formPublicId, workflowPublicId)Workflow
PUT /v1/forms/{form_public_id}/workflows/{workflow_public_id}fomr.workflows.replace(formPublicId, workflowPublicId, document)Workflow
POST /v1/forms/{form_public_id}/workflows/{workflow_public_id}/enablefomr.workflows.enable(formPublicId, workflowPublicId)Workflow
POST /v1/forms/{form_public_id}/workflows/{workflow_public_id}/disablefomr.workflows.disable(formPublicId, workflowPublicId)Workflow
DELETE /v1/forms/{form_public_id}/workflows/{workflow_public_id}fomr.workflows.delete(formPublicId, workflowPublicId)void
GET /v1/integration-connectionsfomr.integrationConnections.list()IntegrationConnection[]
GET /v1/forms/{form_public_id}/submissionsfomr.submissions.list(formPublicId, query)Page<Submission>
GET /v1/forms/{form_public_id}/submissions/{submission_public_id}fomr.submissions.get(formPublicId, submissionPublicId)Submission
GET /v1/forms/{form_public_id}/submissions/exportfomr.submissions.export(formPublicId, query)Response

forms.list(), templates.list(), and submissions.list() return the first Page<T>. Read its data, call nextPage(), or iterate over every result:

const firstPage = await fomr.submissions.list('Ev3ntReg01', { limit: 100 });
for (const submission of firstPage.data) {
process.stdout.write(`${submission.public_id}\n`);
}
const secondPage = await firstPage.nextPage();
for await (const submission of firstPage) {
process.stdout.write(`${submission.public_id}\n`);
}

nextPage() returns null after the last page, and next_cursor holds the raw cursor. Iteration fetches each next page only when it needs it. Every page is one API request.

All SDK errors extend FomrError. HTTP failures extend FomrApiError, which carries the status, the Platform Error code, requestId, response headers, parsed rateLimit state, and the response body. If the response is not JSON, body holds the raw text and code is UNKNOWN.

Error classWhat it represents
FomrConfigurationErrorA missing token, a token provider that returned no token, or an empty, ., or .. public ID.
AuthenticationErrorA 401 authentication failure.
PermissionErrorA 403; requiredPermission names the missing permission when available.
NotFoundErrorA 404 for a missing or inaccessible resource.
ValidationErrorA 400 input failure; issues contains field-level findings.
PublishValidationErrorFORM_PUBLISH_VALIDATION_FAILED; issues contains publish findings.
ConflictErrorA 409 conflict.
PlanErrorA 402 plan limit or paid-feature requirement.
PayloadTooLargeErrorA 413 request-size failure.
ThrottledErrorA 429, including retry timing and limit fields: policy, limit, used, remaining, cost, windowSeconds, resetsAt, retryAfterMs, and upgradeUrl.
ServerErrorA 5xx Platform API failure.
ServiceUnavailableErrorA 503, such as a saturated write pool; a subtype of ServerError.
ConnectionErrorA network failure before an HTTP response arrived.
TimeoutErrorA request that exceeded its timeout; a subtype of ConnectionError.

Narrow errors with instanceof, then read the fields carried by that class:

import { Fomr, PlanError, ThrottledError } from '@fomr/sdk';
try {
await fomr.forms.publish('Ev3ntReg01');
} catch (error) {
if (error instanceof ThrottledError) {
process.stdout.write(`Retry after ${error.retryAfterMs ?? 0} ms\n`);
} else if (error instanceof PlanError) {
process.stdout.write(`${error.feature ?? 'This operation'} needs a different plan.\n`);
} else {
throw error;
}
}

Types for error codes, publish issue codes, form and workflow node types, page types, and statuses accept new string values, and the SDK keeps unknown response fields, form nodes, and workflow nodes. Your code keeps working when /v1 adds values. The Errors reference lists every code.

By default the SDK retries up to two times, with exponential backoff and jitter, waiting at most maxRetryDelayMs (60 seconds).

It retries connection failures and 5xx responses only when repeating the call is safe:

  • Reads, and draft, domain, and workflow replacement.
  • Validate, unpublish, close, reopen, restore, move, access and workspace updates, workflow enable and disable, and template conversion.

It never automatically retries a create, duplicate, publish, any delete (including removing a domain), or token revocation, because a repeat could have a different effect, such as a second copy of a form. Decide in your code whether to try again.

Rate limits follow separate rules for every call:

  • TOO_MANY_REQUESTS from an API Limit is retried when its Retry-After is no longer than maxRetryDelayMs. In practice that covers the 15-minute limit; a used-up 24-hour or 30-day limit waits longer, so the SDK throws and you decide whether to wait until resetsAt or stop the job. See Rate limits and plans.

A call that fails with an error answer creates nothing and spends no credits, so it is safe to send again once you have fixed the cause. If a create fails with a timeout or connection error instead, the form may or may not exist: list your forms before you send the create again.

fomr.request() results include the parsed rateLimit state, and so does every FomrApiError:

const response = await fomr.request('GET', '/v1/usage');
const remaining = response.rateLimit?.['15m']?.remaining;
if (remaining !== null && remaining !== undefined) {
process.stdout.write(`${remaining} credits remain in this 15-minute window\n`);
}

For every window’s totals and reset times without spending credits, call fomr.usage(). See Rate limits and plans for what each field means.

The package exports its version and the Contract Revision it implements:

import {
CONTRACT_REVISION,
Fomr,
PAGINATION_LIMITS,
PUBLIC_ID_ALPHABET,
PUBLIC_ID_LENGTHS,
SDK_VERSION,
nodeTypeEnum,
pageTypeEnum,
} from '@fomr/sdk';
process.stdout.write(`${SDK_VERSION} implements ${CONTRACT_REVISION}\n`);

The same values are available as the static Fomr.version and Fomr.contractRevision. Use PUBLIC_ID_ALPHABET, PUBLIC_ID_LENGTHS, PAGINATION_LIMITS, nodeTypeEnum, and pageTypeEnum instead of copying these values into your code. PUBLIC_ID_LENGTHS.workflow is a maximum, because workflow public IDs vary in length: match them with publicIdPattern(PUBLIC_ID_LENGTHS.workflow, 1).

The matching OpenAPI document is exported as @fomr/sdk/openapi.json.

Node.js 26.12.1 and newer is supported and tested. The SDK uses only standard Fetch APIs, so Bun and edge runtimes can run it, but they are not tested. Browsers are not supported: a Personal Access Token must never be shipped to a browser, and the Platform API sends no browser CORS headers (Not a browser API).

The package stays on 0.x until Platform API /v1 reaches general availability. Each new Contract Revision ships in a new SDK release; check the API changelog before upgrading.

  • Follow Getting started to create, validate, publish, and read a form submission.
  • Read Forms for draft and lifecycle behavior before automating writes.
  • Read Errors for every Platform Error code and its recovery path.
  • Check the API changelog when CONTRACT_REVISION changes.

Let your AI agent build the next form

Connect Claude, ChatGPT or another AI app, or build by hand. Free forever, with unlimited responses.