The QuickBase API for TypeScript and JavaScript, in Node.js, the browser and QuickBase code pages.
const projects = await qb.runQuery({ from: 'bqtable1', where: "{7.EX.'Active'}" }).all();
.all(), so you never write a skip loop.select: ['name', 'status'], with a generator that writes the names from your app.npm install quickbase-js
Create a user token in QuickBase, then:
import { createClient } from 'quickbase-js';
const qb = createClient({
realm: 'mycompany', // mycompany.quickbase.com
auth: { type: 'user-token', userToken: process.env.QB_USER_TOKEN! },
});
const app = await qb.getApp({ appId: 'bpqe82s1' });
console.log(app.name);
const result = await qb.runQuery({
from: 'bqtable1',
select: [3, 6, 7],
where: "{7.EX.'Active'}",
}).all(); // every page
for (const record of result.data ?? []) {
console.log(record['6']?.value);
}
await qb.upsert({
to: 'bqtable1',
data: [{ '6': 'New project', '7': 'Active' }], // plain values are wrapped for you
});
Load the browser bundle and use temporary-token auth. Calls run as the signed-in user, with that user's permissions, and there is no token in your page.
<script src="https://cdn.jsdelivr.net/npm/quickbase-js@3/dist/quickbase.min.js"></script>
<script>
const qb = QuickBase.createClient({
realm: window.location.hostname.split('.')[0],
auth: { type: 'temp-token' },
});
qb.getApp({ appId: 'bpqe82s1' }).then((app) => console.log(app.name));
</script>
As a module: import { createClient } from 'https://cdn.jsdelivr.net/npm/quickbase-js@3/dist/quickbase.esm.js'.
examples/codepages has a complete, read-only code page in plain JavaScript, Preact, React, Vue and Angular: a live feed of what changed across every table in the app. Paste one into a new code page; there's nothing to configure.
const all = await qb.runQuery({ from: 'bqtable1' }).all();
const first500 = await qb.runQuery({ from: 'bqtable1' }).paginate({ limit: 500 });
const page = await qb.runQuery({ from: 'bqtable1' }); // one page
QuickBase returns a page at a time. runQuery, runReport, getUsers and the other paginated methods return one page when awaited, and follow the pages with .all() or .paginate(). Set autoPaginate: true on the client to make a plain await fetch them all.
await qb.runQuery({
from: 'bqtable1',
select: [3, 6, 7],
where: '{6.GT.100}',
sortBy: [{ fieldId: 3, order: 'ASC' }],
options: { top: 100, skip: 0 },
});
where uses QuickBase's query syntax: {field.OPERATOR.'value'}, joined with AND and OR.
const reportRows = await qb.runReport({ reportId: '7', tableId: 'bqtable1' }).all();
upsert adds records, or updates the one whose merge field matches (the key field, usually Record ID#, when you don't name one):
const result = await qb.upsert({
to: 'bqtable1',
mergeFieldId: 9,
data: [{ '9': { value: 'EXT-001' }, '6': { value: 'Alpha' } }],
fieldsToReturn: [6],
});
console.log(result.metadata?.createdRecordIds, result.metadata?.updatedRecordIds);
await qb.deleteRecords({ from: 'bqtable1', where: '{3.EX.123}' });
Give the client a schema and use your names anywhere an ID goes. Records come back keyed by name, with plain values:
const qb = createClient({
realm: 'mycompany',
auth: { type: 'user-token', userToken: 'token' },
schema: { tables: { projects: { id: 'bqw3ryzab', fields: { id: 3, name: 6, status: 7 } } } },
});
const result = await qb.runQuery({
from: 'projects',
select: ['name', 'status'],
where: "{'status'.EX.'Active'}",
});
console.log(result.data[0]?.name, result.data[0]?.status);
await qb.upsert({ to: 'projects', data: [{ name: 'Alpha', status: 'Active' }] });
Generate the schema from your app instead of writing it, and regenerate with --merge when the app changes (your renamed aliases are kept):
npx quickbase-js schema -r mycompany -a bpqe82s1 -t "$QB_USER_TOKEN" -o schema.ts
The generated schema also records each field's QuickBase type, which types results and upserts by name: result.data[0].dueDate is a QuickbaseDate, and a misspelled field, a wrong value type or a write to a formula field is a compile error. A misspelled name in plain JavaScript throws with a suggestion (Did you mean 'status'?). The schema guide has the details.
const tables = await qb.getAppTables({ appId: 'bpqe82s1' });
console.log(tables.map((t) => `${t.id} ${t.name}`));
const fields = await qb.getFields({ tableId: 'bqtable1' });
console.log(fields.map((f) => `${f.id} ${f.label} (${f.fieldType})`));
Solutions are QBL (YAML) and files are raw content, so these take and return text:
const qbl = await qb.exportSolution({ solutionId: 'solution-id' });
await qb.updateSolution({ solutionId: 'solution-id' }, qbl);
const file = await qb.downloadFile({ tableId: 'bqtable1', recordId: 12, fieldId: 8, versionNumber: 0 }); // base64
The JSON API doesn't cover these, so createXmlClient(qb) calls the XML API with the same authentication, retries, read-only mode and schema:
import { createXmlClient } from 'quickbase-js';
const xml = createXmlClient(qb);
const roles = await xml.getRoleInfo(appId);
for (const role of roles.roles) {
console.log(role.name, role.access.description);
}
Every method is in the XML API guide.
const result = await qb.request<{ id: string }>({ method: 'GET', path: '/apps/bpqe82s1' });
request uses the client's authentication, retries and throttling.
auth.type |
Use it for |
|---|---|
'user-token' |
Servers and scripts |
'temp-token' |
Code pages and other browser code inside QuickBase |
'ticket' |
A user signing in with their QuickBase email and password |
'sso' |
A user signed in through your identity provider (SAML) |
Details are in the authentication guide.
QuickBase allows 100 requests per 10 seconds per user token. The client retries 429s with exponential backoff, honoring Retry-After, and retries timeouts and server errors for reads; a write that may have been applied isn't sent twice. It can throttle itself so it never hits the limit:
createClient({
realm: 'mycompany',
auth: { type: 'user-token', userToken: 'token' },
rateLimit: {
proactiveThrottle: { enabled: true, requestsPer10Seconds: 100 },
retry: { maxAttempts: 5 },
},
});
Timeouts, backoff settings, a rate-limit callback, cancelling with withSignal, and throwOnLineErrors are in the reliability guide.
Every error extends QuickbaseError, with a class for each kind of failure:
import { RateLimitError, NotFoundError, ReadOnlyError, QuickbaseError } from 'quickbase-js';
try {
await qb.getApp({ appId: 'bpqe82s1' });
} catch (error) {
if (error instanceof RateLimitError) {
console.log(`rate limited; retry after ${error.retryAfter}s`);
} else if (error instanceof NotFoundError) {
console.log('no such app');
} else if (error instanceof ReadOnlyError) {
console.log(`write blocked: ${error.method} ${error.path}`);
} else if (error instanceof QuickbaseError) {
console.log(`QuickBase error ${error.statusCode}: ${error.message}`);
}
}
| Class | Status |
|---|---|
ValidationError |
400 |
AuthenticationError |
401 |
AuthorizationError |
403 |
NotFoundError |
404 |
RateLimitError |
429 |
ServerError |
5xx |
ReadOnlyError |
a write blocked by readOnly: true |
WriteScopeError |
a write outside writeScope |
WriteBlockedError |
either of the two above (their base class) |
TimeoutError |
no answer within timeout |
NetworkError |
no answer at all (DNS, connection) |
LineErrorsError |
an upsert's rejected values, with throwOnLineErrors: true |
The XML API adds QuickbaseTicketError, QuickbaseAppTokenError and QuickbaseXmlError.
Path parameters are URL-encoded by every typed method, so an ID stays one path segment: getApp({ appId: '../x' }) asks for an app named ../x, not another endpoint.
readOnly: true refuses every write before it is sent, in both APIs. Reads sent as POST (runQuery, runReport, recordsModifiedSince, audit) still work. It, and writeScope, fail closed: an XML action counts as a write unless it is known to only read, in any letter case (isXmlWriteAction('API_DeleteDatabase') is true); a path a server could read as another path (.., \, %, ? or // in a path given to request()) is refused, read or write; an XML call's dbid must be a plain ID; a request with a method-override header is refused; write endpoints are matched without regard to letter case; and a body is checked and sent as one plain copy, so a toJSON can't change it in between. getConfig() returns a frozen copy, so neither setting can be changed after the client is created.
writeScope limits writes to what it names, in both APIs; anything else throws WriteScopeError before it is sent. Reads are never limited, and with readOnly: true as well nothing is written. A write whose target can be checked is allowed when the target is listed; a write that creates something, or acts on the realm's users or your own credentials, is allowed by a switch:
writeScope: {
appIds: [appId], // the apps, and every table in them (including new ones)
createApps: false, // createApp, copyApp; XML create and clone database
solutionIds: [], // updateSolution, updateSolutionToRecord
createSolutions: false, // createSolution, createSolutionFromRecord
groupIds: [], // members, managers, subgroups; XML rename and delete (matched as written: '1217', '1217.dgpt')
createGroups: false, // XML create and copy group
manageUsers: false, // deny and undeny users; XML provision user (with the app in appIds)
manageTokens: false, // clone, transfer, deactivate, delete user tokens; XML sign-out
}
The client lists the scope's apps' tables (getAppTables) to tell which app a table is in, and refuses the write if that fails. A relationship's parent table must be in scope too. XML writes are checked by dbid, or by the one <gid> for group actions (a comment, CDATA or second <gid> is refused). A relationship's parent is required on create and looked up on update and delete. A body or query that has a checked key in two letter cases (to and To) is refused. changesetSolution only lists what an update would change, so readOnly and writeScope let it through.
What readOnly and writeScope are for. They stop writes a caller didn't mean to allow: a mistake, a careless call, or an AI agent working through your tool that tries something it shouldn't. A refused write's error says so plainly, so whoever reads it (a person or an agent) knows not to retry it or route around it. They don't stop code in the same program that sets out to get around them: such code holds the token and can call fetch without this client. To protect a realm from that, give the token's user only the permissions it needs in QuickBase.
Dates: in query and report results, Date fields are QuickbaseDate and Date/Time fields QuickbaseDateTime, both Dates that show the stored day in any time zone and write back as their field expects. Upserting a plain Date throws: say which kind it is. See dates; convertDates: false keeps the strings.
Requirements: Node.js 18 or later, or any modern browser. The package is ES modules; the browser bundle also defines a QuickBase global.
git clone --recurse-submodules https://github.com/DrewBradfordXYZ/quickbase-js.git
npm install
npm test # unit tests
npm run typecheck # the library, and the docs' examples
npm run spec:build # regenerate the types from the pinned spec in spec/
spec/ is a submodule of quickbase-spec, and CI fails when the generated types don't match it. The code in this README and guides/ comes from examples/docs.ts, which npm run typecheck checks; change them together.
MIT