@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.
Install the SDK
Section titled “Install the SDK”pnpm add @fomr/sdkSet a Personal Access Token in your environment:
read -rs FOMR_TOKENexport FOMR_TOKENCreate tokens under Settings > API; see Authentication. The SDK reads FOMR_TOKEN when you omit the token option.
Create a client
Section titled “Create a client”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.
Client options
Section titled “Client options”new Fomr(options) accepts these options:
| Option | Type | Default | What it controls |
|---|---|---|---|
token | string | () => string | Promise<string> | FOMR_TOKEN | The Personal Access Token. A function runs before every attempt, so you can rotate tokens. |
baseUrl | string | https:/ | The 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. |
fetch | typeof globalThis.fetch | globalThis.fetch | A Fetch implementation, for tests or custom networking. Treat it as trusted code. |
headers | HeadersInit | None | Headers added to every request. The SDK always sets its own Authorization and User-Agent. |
userAgent | string | None | Your product identifier, placed before fomr-sdk/. |
timeoutMs | number | 30000 | Request timeout in milliseconds. |
maxRetries | number | 2 | Automatic retries after the first attempt. |
maxRetryDelayMs | number | 60000 | The 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',});Request options
Section titled “Request options”Every method accepts a final options object for that one call:
signal,headers,timeoutMs, andmaxRetries.dryRun: trueonforms.create(),templates.create(),forms.updateDraft(),workflows.create(), andworkflows.replace(). The server validates and resolves the document without storing anything.workspace_public_idonforms.create()andtemplates.create(), to create outside the Default Workspace.
Use resource namespaces
Section titled “Use resource namespaces”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`);Themes
Section titled “Themes”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 } });Private Templates
Section titled “Private Templates”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.
Workspaces
Section titled “Workspaces”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.
Workflows
Section titled “Workflows”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.
Submissions
Section titled “Submissions”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, usage, and raw requests
Section titled “Identity, usage, and raw requests”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.
Find an operation
Section titled “Find an operation”Every Platform API operation and its SDK method:
| HTTP operation | SDK call | Result |
|---|---|---|
GET / | fomr.me() | Me |
DELETE / | fomr.revokeCurrentToken() | RevokedToken |
GET / | fomr.usage() | Usage |
GET / | fomr.forms.list(query) or fomr.templates.list(query) | Page<Form> |
POST / | fomr.forms.create(blueprint) or fomr.templates.create(blueprint) | CreatedForm |
GET / | fomr.forms.get(formPublicId) | Form |
DELETE / | fomr.forms.delete(formPublicId) | void |
POST / | fomr.forms.restore(formPublicId) | Form |
POST / | fomr.forms.move(formPublicId, workspacePublicId) | Form |
GET / | fomr.forms.getDraft(formPublicId) | DraftDocument |
PUT / | fomr.forms.updateDraft(formPublicId, blueprint) | DraftWriteResult |
GET / | fomr.forms.getPublished(formPublicId) | CanonicalBlueprint |
POST / | fomr.forms.validate(formPublicId) | FormValidationResult |
POST / | fomr.forms.publish(formPublicId) | Form |
POST / | fomr.forms.unpublish(formPublicId) | Form |
POST / | fomr.forms.close(formPublicId) | Form |
POST / | fomr.forms.reopen(formPublicId) | Form |
PATCH / | fomr.forms.updateAccess(formPublicId, input) | Form |
POST / | fomr.forms.duplicate(formPublicId, input) or fomr.templates.createForm(templatePublicId, input) | CreatedForm |
POST / | fomr.forms.markTemplate(formPublicId) | Form |
PUT / | fomr.forms.setDomain(formPublicId, input) | Form |
DELETE / | fomr.forms.removeDomain(formPublicId) | Form |
GET / | fomr.workspaces.list() | Workspace[] |
POST / | fomr.workspaces.create(input) | Workspace |
GET / | fomr.workspaces.get(workspacePublicId) | Workspace |
PATCH / | fomr.workspaces.update(workspacePublicId, input) | Workspace |
GET / | fomr.themes.list() | Theme[] |
GET / | fomr.themes.get(themeId) | Theme |
GET / | fomr.domains.list() | Domain[] |
GET / | fomr.workflows.list(formPublicId) | WorkflowSummary[] |
POST / | fomr.workflows.create(formPublicId, document) | Workflow |
GET / | fomr.workflows.get(formPublicId, workflowPublicId) | Workflow |
PUT / | fomr.workflows.replace(formPublicId, workflowPublicId, document) | Workflow |
POST / | fomr.workflows.enable(formPublicId, workflowPublicId) | Workflow |
POST / | fomr.workflows.disable(formPublicId, workflowPublicId) | Workflow |
DELETE / | fomr.workflows.delete(formPublicId, workflowPublicId) | void |
GET / | fomr.integrationConnections.list() | IntegrationConnection[] |
GET / | fomr.submissions.list(formPublicId, query) | Page<Submission> |
GET / | fomr.submissions.get(formPublicId, submissionPublicId) | Submission |
GET / | fomr.submissions.export(formPublicId, query) | Response |
Follow cursor pagination
Section titled “Follow cursor pagination”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.
Handle errors
Section titled “Handle errors”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 class | What it represents |
|---|---|
FomrConfigurationError | A missing token, a token provider that returned no token, or an empty, ., or .. public ID. |
AuthenticationError | A 401 authentication failure. |
PermissionError | A 403; requiredPermission names the missing permission when available. |
NotFoundError | A 404 for a missing or inaccessible resource. |
ValidationError | A 400 input failure; issues contains field-level findings. |
PublishValidationError | FORM_PUBLISH_VALIDATION_FAILED; issues contains publish findings. |
ConflictError | A 409 conflict. |
PlanError | A 402 plan limit or paid-feature requirement. |
PayloadTooLargeError | A 413 request-size failure. |
ThrottledError | A 429, including retry timing and limit fields: policy, limit, used, remaining, cost, windowSeconds, resetsAt, retryAfterMs, and upgradeUrl. |
ServerError | A 5xx Platform API failure. |
ServiceUnavailableError | A 503, such as a saturated write pool; a subtype of ServerError. |
ConnectionError | A network failure before an HTTP response arrived. |
TimeoutError | A 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.
Understand retries
Section titled “Understand retries”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_REQUESTSfrom an API Limit is retried when itsRetry-Afteris no longer thanmaxRetryDelayMs. 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 untilresetsAtor 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.
Read rate-limit state
Section titled “Read rate-limit state”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.
Use contract metadata and constants
Section titled “Use contract metadata and constants”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.
Runtime support and versioning
Section titled “Runtime support and versioning”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.
Next steps
Section titled “Next steps”- 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_REVISIONchanges.