Browse and search developers
/
REST API
JavaScript and TypeScript SDK
Use @formitai/sdk for typed REST API calls with automatic retries and pagination, OAuth helpers and webhook verification.
The @formitai/sdk package wraps the REST API with one typed method per endpoint, generated from the same OpenAPI document as the API reference. It runs on Node.js 18 or later.
Install
npm install @formitai/sdkTypeScript
import { FormitClient } from '@formitai/sdk';
const formit = new FormitClient({ token: process.env.FORMIT_API_KEY! });
const form = await formit.createForm({
name: 'Product feedback',
questions: [{ type: 'email', title: 'Your work email', required: true }],
});
await formit.publishForm({ formId: form.id });
for await (const response of formit.paginate((cursor) =>
formit.listResponses({ formId: form.id }, { cursor, limit: 100 }),
)) {
console.log(response.id, response.answers);
}- Retries: reads, deletes and creates are retried on
429and5xx(3 times by default, honouringRetry-After). Creates send anIdempotency-Keyautomatically, so a retry never creates a duplicate. Other writes are not retried. - Errors: failed calls throw
FormitApiErrorwithstatus,type,code,messageandrequestId. - Pagination:
paginate()turns any list call into an async iterator over every item. - OAuth apps:
FormitOAuthbuilds the authorize URL, exchanges codes (withcreatePkcePair()for PKCE), refreshes and revokes tokens. - Webhooks:
verifyWebhook()from@formitai/sdk/webhookschecks the signature and timestamp and returns the parsed event.
Related
Can't find what you need?