UNPKG

quickbase

Version:

A lightweight, typed, promise-based Quickbase API, autogenerated from the OpenAPI spec

1,007 lines (893 loc) 243 kB
'use strict'; /* Dependencies */ import merge from 'deepmerge'; import { debug } from 'debug'; import { Throttle } from 'generic-throttle'; import axios, { AxiosRequestConfig, AxiosResponse } from 'axios'; /* Debug */ const debugMain = debug('quickbase:main'); const debugRequest = debug('quickbase:request'); const debugResponse = debug('quickbase:response'); /* Globals */ const VERSION = require('../package.json').version; const IS_BROWSER = typeof(window) !== 'undefined'; /* Helpers */ const delay = (time: number) => { return new Promise((resolve) => { setTimeout(resolve, +time); }); }; const getRetryDelay = (headers: { 'retry-after'?: string; 'x-ratelimit-reset'?: string; }) => { const retryAfter = headers['retry-after']; if(retryAfter){ let retryDelay = Math.round(parseFloat(retryAfter) * 1000); if (isNaN(retryDelay)) { retryDelay = Math.max(0, new Date(retryAfter).valueOf() - new Date().valueOf()); } return retryDelay; } return +(headers['x-ratelimit-reset'] || 10000); }; type LowerKeysObject<T extends object> = { [K in keyof T as (K extends string ? Lowercase<K> : K)]: T[K] }; const objKeysToLowercase = <T extends object>(obj: T): LowerKeysObject<T> => { return Object.fromEntries(Object.entries(obj).map(([key, value]) => [ key.toLocaleLowerCase(), value ])) as LowerKeysObject<T>; }; /* Quickbase Error */ export type QuickBaseErrorJSON = { code: number; message: string; description: string; rayId: string; }; export class QuickBaseError extends Error { /** * Extends the native JavaScript `Error` object for use with Quickbase API errors * * Example: * ```typescript * const qbErr = new QuickBaseError(403, 'Access Denied', 'User token is invalid', 'xxxx'); * ``` * * @param code Error code * @param message Error message * @param description Error description * @param rayId Quickbase API Ray ID */ constructor(public code: number, public message: string, public description: string, public rayId: string) { super(message); } /** * Serialize the QuickBaseError instance into JSON */ toJSON(): QuickBaseErrorJSON { return { code: this.code, message: this.message, description: this.description, rayId: this.rayId }; } /** * Rebuild the QuickBaseError instance from serialized JSON * * @param json Serialized QuickBaseError class options */ fromJSON(json: string | QuickBaseErrorJSON): QuickBaseError { if(typeof(json) === 'string'){ json = JSON.parse(json); } if(typeof(json) !== 'object'){ throw new TypeError('json argument must be type of object or a valid JSON string'); } this.code = json.code; this.message = json.message; this.description = json.description; this.rayId = json.rayId; return this; } /** * Create a new QuickBase instance from serialized JSON * * @param json Serialized QuickBaseError class options */ static fromJSON(json: string | QuickBaseErrorJSON): QuickBaseError { if(typeof(json) === 'string'){ json = JSON.parse(json); } if(typeof(json) !== 'object'){ throw new TypeError('json argument must be type of object or a valid JSON string'); } return new QuickBaseError(json.code, json.message, json.description, json.rayId); } } /* Main Class */ export class QuickBase { public readonly CLASS_NAME: string = 'QuickBase'; static readonly CLASS_NAME: string = 'QuickBase'; static readonly VERSION: string = VERSION; /** * The default settings of a `QuickBase` instance */ static defaults: Required<QuickBaseOptions> = { server: 'api.quickbase.com', version: 'v1', realm: IS_BROWSER ? window.location.host.split('.')[0] : '', userToken: '', tempToken: '', tempTokenDbid: '', appToken: '', userAgent: '', autoRenewTempTokens: true, connectionLimit: 10, connectionLimitPeriod: 1000, errorOnConnectionLimit: false, retryOnQuotaExceeded: true, proxy: false }; /** * The internal numerical id for API calls. * * Increments by 1 with each request. */ private _id: number = 0; /** * The internal throttler for rate-limiting API calls */ private throttle: Throttle; /** * The `QuickBase` instance settings */ public settings: Required<QuickBaseOptions>; constructor(options?: QuickBaseOptions){ this.settings = merge(QuickBase.defaults, options || {}); this.throttle = new Throttle(this.settings.connectionLimit, this.settings.connectionLimitPeriod, this.settings.errorOnConnectionLimit); debugMain('New Instance', this.settings); return this; } private assignAuthorizationHeaders(headers?: AxiosRequestConfig['headers'], addToken = true) { if(!headers){ headers = {}; } if(this.settings.userToken){ if(addToken){ headers.Authorization = `QB-USER-TOKEN ${this.settings.userToken}`; } }else{ if(this.settings.appToken){ headers['QB-App-Token'] = this.settings.appToken; } if(addToken && this.settings.tempToken){ headers.Authorization = `QB-TEMP-TOKEN ${this.settings.tempToken}`; } } return headers; } private getBaseRequest(){ return { method: 'GET', baseURL: `https://${this.settings.server}/${this.settings.version}`, headers: { 'Content-Type': 'application/json; charset=UTF-8', [IS_BROWSER ? 'X-User-Agent' : 'User-Agent']: `${this.settings.userAgent} node-quickbase/v${VERSION} ${IS_BROWSER ? (window.navigator ? window.navigator.userAgent : '') : 'nodejs/' + process.version}`.trim(), 'QB-Realm-Hostname': this.settings.realm }, proxy: this.settings.proxy }; } private async request<T = any>(options: AxiosRequestConfig, attempt = 0): Promise<AxiosResponse<T>> { const id = 0 + (++this._id); try { debugRequest(id, options); options.headers = this.assignAuthorizationHeaders(options.headers, !options.url?.startsWith('/auth/temporary')); const results = await axios.request<T>(options); debugResponse(id, results); return results; }catch(err: any){ if(err.response){ const headers = objKeysToLowercase<{ 'x-ratelimit-reset': string; 'retry-after': string; 'qb-api-ray': string; }>(err.response.headers); const qbErr = new QuickBaseError( err.response.status, err.response.data.message, err.response.data.description, headers['qb-api-ray'] ); debugResponse(id, 'Quickbase Error', qbErr); if(this.settings.retryOnQuotaExceeded && qbErr.code === 429){ const delayMs = getRetryDelay(headers); debugResponse(id, `Waiting ${delayMs}ms until retrying...`); await delay(delayMs); debugResponse(id, `Retrying...`); return await this.request<T>(options); } if(attempt >= 3){ throw qbErr; } const errDescription = '' + (qbErr.description || ''); if(this.settings.autoRenewTempTokens && this.settings.tempTokenDbid && ( errDescription.match(/Your ticket has expired/i) || errDescription.match(/Invalid Authorization/i) || errDescription.match(/Required header 'authorization' not found/i) )){ debugResponse(id, `Getting new temporary ticket for ${this.settings.tempTokenDbid}...`); const results = await this.request(merge.all([ this.getBaseRequest(), { url: `auth/temporary/${this.settings.tempTokenDbid}`, withCredentials: true } ]), attempt + 1); this.setTempToken(this.settings.tempTokenDbid, results.data.temporaryAuthorization); debugResponse(id, `Retrying...`); return await this.request<T>(options, attempt + 1); } throw qbErr; } debugResponse(id, 'Error', err); throw err; } } private async api<T = any>(actOptions: AxiosRequestConfig, reqOptions?: AxiosRequestConfig): Promise<AxiosResponse<T>> { return this.throttle.acquire(async () => { return await this.request<T>(merge.all([ this.getBaseRequest(), actOptions, reqOptions || {} ])); }); } /** * Set the internally stored `tempToken` for use in subsequent API calls * * Example: * ```typescript * qb.setTempToken('xxxx.xxx[...]xxx', 'xxxxxxxxx'); * ``` * * @param dbid Quickbase Application ID or Table ID * @param tempToken Temporary Quickbase Authentication Token */ setTempToken(dbid: string, tempToken: string): QuickBase { this.settings.tempTokenDbid = dbid; this.settings.tempToken = tempToken; return this; } /** * Rebuild the QuickBase instance from serialized JSON * * @param json QuickBase class options */ fromJSON(json: string | QuickBaseOptions): QuickBase { if(typeof(json) === 'string'){ json = JSON.parse(json); } if(typeof(json) !== 'object'){ throw new TypeError('json argument must be type of object or a valid JSON string'); } this.settings = merge(this.settings, json); return this; } /** * Serialize the QuickBase instance into JSON */ toJSON(): Required<QuickBaseOptions> { return merge({}, this.settings); } /** * Create a new QuickBase instance from serialized JSON * * @param json QuickBase class options */ static fromJSON(json: string | QuickBaseOptions): QuickBase { if(typeof(json) === 'string'){ json = JSON.parse(json); } if(typeof(json) !== 'object'){ throw new TypeError('json argument must be type of object or a valid JSON string'); } return new QuickBase(json); } /** * Test if a variable is a `quickbase` object * * @param obj A variable you'd like to test */ static IsQuickBase(obj: any): obj is QuickBase { return ((obj || {}) as QuickBase).CLASS_NAME === QuickBase.CLASS_NAME; } /** * Create an app * * Creates an application in an account. You must have application creation rights in the respective account. Main properties and application variables can be set with this API. * * [Quickbase Documentation](https://developer.quickbase.com/operation/createApp) * * @param options Create an app method options object * @param options.assignToken Set to true if you would like to assign the app to the user token you used to create the application. The default is false. * @param options.variables[].name The name for the variable. * @param options.variables[].value The value for the variable. * @param options.name The app name. You are allowed to create multiple apps with the same name, in the same realm, because they will have different dbid values. We urge you to be careful about doing this. * @param options.securityProperties.hideFromPublic Hide from public application searches * @param options.securityProperties.mustBeRealmApproved Only "approved" users may access this application * @param options.securityProperties.allowClone Allow users who are not administrators to copy * @param options.securityProperties.useIPFilter Only users logging in from "approved" IP addresses may access this application * @param options.securityProperties.allowExport Allow users who are not administrators to export data * @param options.securityProperties.enableAppTokens Require Application Tokens * @param options.description The description for the app. If this property is left out, the app description will be blank. * @param options.requestOptions Override axios request configuration * @param options.returnAxios If `true`, the returned object will be the entire `AxiosResponse` object */ public async createApp({ requestOptions, returnAxios, ...body }: QuickBaseRequestCreateApp & { returnAxios?: false }): Promise<QuickBaseResponseCreateApp>; public async createApp({ requestOptions, returnAxios, ...body }: QuickBaseRequestCreateApp & { returnAxios: true }): Promise<AxiosResponse<QuickBaseResponseCreateApp>>; public async createApp({ requestOptions, returnAxios = false, ...body }: QuickBaseRequestCreateApp): Promise<QuickBaseResponseCreateApp | AxiosResponse<QuickBaseResponseCreateApp>> { const results = await this.api<QuickBaseResponseCreateApp>({ method: 'POST', url: `/apps`, data: body, }, requestOptions); return returnAxios ? results : results.data; } /** * Get an app * * Returns the main properties of an application, including application variables. * * [Quickbase Documentation](https://developer.quickbase.com/operation/getApp) * * @param options Get an app method options object * @param options.appId The unique identifier of an app * @param options.requestOptions Override axios request configuration * @param options.returnAxios If `true`, the returned object will be the entire `AxiosResponse` object */ public async getApp({ appId, requestOptions, returnAxios }: QuickBaseRequestGetApp & { returnAxios?: false }): Promise<QuickBaseResponseGetApp>; public async getApp({ appId, requestOptions, returnAxios }: QuickBaseRequestGetApp & { returnAxios: true }): Promise<AxiosResponse<QuickBaseResponseGetApp>>; public async getApp({ appId, requestOptions, returnAxios = false }: QuickBaseRequestGetApp): Promise<QuickBaseResponseGetApp | AxiosResponse<QuickBaseResponseGetApp>> { const results = await this.api<QuickBaseResponseGetApp>({ method: 'GET', url: `/apps/${appId}`, }, requestOptions); return returnAxios ? results : results.data; } /** * Update an app * * Updates the main properties and/or application variables for a specific application. Any properties of the app that you do not specify in the request body will remain unchanged. * * [Quickbase Documentation](https://developer.quickbase.com/operation/updateApp) * * @param options Update an app method options object * @param options.appId The unique identifier of an app * @param options.variables[].name The name for the variable. * @param options.variables[].value The value for the variable. * @param options.name The name for the app. * @param options.securityProperties.hideFromPublic Hide from public application searches * @param options.securityProperties.mustBeRealmApproved Only "approved" users may access this application * @param options.securityProperties.allowClone Allow users who are not administrators to copy * @param options.securityProperties.useIPFilter Only users logging in from "approved" IP addresses may access this application * @param options.securityProperties.allowExport Allow users who are not administrators to export data * @param options.securityProperties.enableAppTokens Require Application Tokens * @param options.description The description for the app. * @param options.requestOptions Override axios request configuration * @param options.returnAxios If `true`, the returned object will be the entire `AxiosResponse` object */ public async updateApp({ appId, requestOptions, returnAxios, ...body }: QuickBaseRequestUpdateApp & { returnAxios?: false }): Promise<QuickBaseResponseUpdateApp>; public async updateApp({ appId, requestOptions, returnAxios, ...body }: QuickBaseRequestUpdateApp & { returnAxios: true }): Promise<AxiosResponse<QuickBaseResponseUpdateApp>>; public async updateApp({ appId, requestOptions, returnAxios = false, ...body }: QuickBaseRequestUpdateApp): Promise<QuickBaseResponseUpdateApp | AxiosResponse<QuickBaseResponseUpdateApp>> { const results = await this.api<QuickBaseResponseUpdateApp>({ method: 'POST', url: `/apps/${appId}`, data: body, }, requestOptions); return returnAxios ? results : results.data; } /** * Delete an app * * Deletes an entire application, including all of the tables and data. * * [Quickbase Documentation](https://developer.quickbase.com/operation/deleteApp) * * @param options Delete an app method options object * @param options.appId The unique identifier of an app * @param options.name To confirm application deletion we ask for application name. * @param options.requestOptions Override axios request configuration * @param options.returnAxios If `true`, the returned object will be the entire `AxiosResponse` object */ public async deleteApp({ appId, requestOptions, returnAxios, ...body }: QuickBaseRequestDeleteApp & { returnAxios?: false }): Promise<QuickBaseResponseDeleteApp>; public async deleteApp({ appId, requestOptions, returnAxios, ...body }: QuickBaseRequestDeleteApp & { returnAxios: true }): Promise<AxiosResponse<QuickBaseResponseDeleteApp>>; public async deleteApp({ appId, requestOptions, returnAxios = false, ...body }: QuickBaseRequestDeleteApp): Promise<QuickBaseResponseDeleteApp | AxiosResponse<QuickBaseResponseDeleteApp>> { const results = await this.api<QuickBaseResponseDeleteApp>({ method: 'DELETE', url: `/apps/${appId}`, data: body, }, requestOptions); return returnAxios ? results : results.data; } /** * Get app events * * Get a list of events that can be triggered based on data or user actions in this application, includes: Email notification, Reminders, Subscriptions, QB Actions, Webhooks, record change triggered Automations (does not include scheduled). * * [Quickbase Documentation](https://developer.quickbase.com/operation/getAppEvents) * * @param options Get app events method options object * @param options.appId The unique identifier of an app * @param options.requestOptions Override axios request configuration * @param options.returnAxios If `true`, the returned object will be the entire `AxiosResponse` object */ public async getAppEvents({ appId, requestOptions, returnAxios }: QuickBaseRequestGetAppEvents & { returnAxios?: false }): Promise<QuickBaseResponseGetAppEvents>; public async getAppEvents({ appId, requestOptions, returnAxios }: QuickBaseRequestGetAppEvents & { returnAxios: true }): Promise<AxiosResponse<QuickBaseResponseGetAppEvents>>; public async getAppEvents({ appId, requestOptions, returnAxios = false }: QuickBaseRequestGetAppEvents): Promise<QuickBaseResponseGetAppEvents | AxiosResponse<QuickBaseResponseGetAppEvents>> { const results = await this.api<QuickBaseResponseGetAppEvents>({ method: 'GET', url: `/apps/${appId}/events`, }, requestOptions); return returnAxios ? results : results.data; } /** * Copy an app * * Copies the specified application. The new application will have the same schema as the original. See below for additional copy options. * * [Quickbase Documentation](https://developer.quickbase.com/operation/copyApp) * * @param options Copy an app method options object * @param options.appId The unique identifier of an app * @param options.name The name of the newly copied app * @param options.description The description of the newly copied app * @param options.properties.assignUserToken Whether to add the user token used to make this request to the new app * @param options.properties.excludeFiles If keepData is true, whether to copy the file attachments as well. If keepData is false, this property is ignored * @param options.properties.keepData Whether to copy the app's data along with the schema * @param options.properties.usersAndRoles If true, users will be copied along with their assigned roles. If false, users and roles will be copied but roles will not be assigned * @param options.requestOptions Override axios request configuration * @param options.returnAxios If `true`, the returned object will be the entire `AxiosResponse` object */ public async copyApp({ appId, requestOptions, returnAxios, ...body }: QuickBaseRequestCopyApp & { returnAxios?: false }): Promise<QuickBaseResponseCopyApp>; public async copyApp({ appId, requestOptions, returnAxios, ...body }: QuickBaseRequestCopyApp & { returnAxios: true }): Promise<AxiosResponse<QuickBaseResponseCopyApp>>; public async copyApp({ appId, requestOptions, returnAxios = false, ...body }: QuickBaseRequestCopyApp): Promise<QuickBaseResponseCopyApp | AxiosResponse<QuickBaseResponseCopyApp>> { const results = await this.api<QuickBaseResponseCopyApp>({ method: 'POST', url: `/apps/${appId}/copy`, data: body, }, requestOptions); return returnAxios ? results : results.data; } /** * Create a table * * Creates a table in an application. * * [Quickbase Documentation](https://developer.quickbase.com/operation/createTable) * * @param options Create a table method options object * @param options.appId The unique identifier of an app * @param options.name The name for the table. * @param options.pluralRecordName The plural noun for records in the table. If this value is not passed the default value is 'Records'. * @param options.singleRecordName The singular noun for records in the table. If this value is not passed the default value is 'Record'. * @param options.description The description for the table. If this value is not passed the default value is blank. * @param options.requestOptions Override axios request configuration * @param options.returnAxios If `true`, the returned object will be the entire `AxiosResponse` object */ public async createTable({ appId, requestOptions, returnAxios, ...body }: QuickBaseRequestCreateTable & { returnAxios?: false }): Promise<QuickBaseResponseCreateTable>; public async createTable({ appId, requestOptions, returnAxios, ...body }: QuickBaseRequestCreateTable & { returnAxios: true }): Promise<AxiosResponse<QuickBaseResponseCreateTable>>; public async createTable({ appId, requestOptions, returnAxios = false, ...body }: QuickBaseRequestCreateTable): Promise<QuickBaseResponseCreateTable | AxiosResponse<QuickBaseResponseCreateTable>> { const results = await this.api<QuickBaseResponseCreateTable>({ method: 'POST', url: `/tables`, data: body, params: { appId } }, requestOptions); return returnAxios ? results : results.data; } /** * Get tables for an app * * Gets a list of all the tables that exist in a specific application. The properties for each table are the same as what is returned in Get table. * * [Quickbase Documentation](https://developer.quickbase.com/operation/getAppTables) * * @param options Get tables for an app method options object * @param options.appId The unique identifier of an app * @param options.requestOptions Override axios request configuration * @param options.returnAxios If `true`, the returned object will be the entire `AxiosResponse` object */ public async getAppTables({ appId, requestOptions, returnAxios }: QuickBaseRequestGetAppTables & { returnAxios?: false }): Promise<QuickBaseResponseGetAppTables>; public async getAppTables({ appId, requestOptions, returnAxios }: QuickBaseRequestGetAppTables & { returnAxios: true }): Promise<AxiosResponse<QuickBaseResponseGetAppTables>>; public async getAppTables({ appId, requestOptions, returnAxios = false }: QuickBaseRequestGetAppTables): Promise<QuickBaseResponseGetAppTables | AxiosResponse<QuickBaseResponseGetAppTables>> { const results = await this.api<QuickBaseResponseGetAppTables>({ method: 'GET', url: `/tables`, params: { appId } }, requestOptions); return returnAxios ? results : results.data; } /** * Get a table * * Gets the properties of an individual table that is part of an application. * * [Quickbase Documentation](https://developer.quickbase.com/operation/getTable) * * @param options Get a table method options object * @param options.tableId The unique identifier (dbid) of the table. * @param options.appId The unique identifier of an app * @param options.requestOptions Override axios request configuration * @param options.returnAxios If `true`, the returned object will be the entire `AxiosResponse` object */ public async getTable({ tableId, appId, requestOptions, returnAxios }: QuickBaseRequestGetTable & { returnAxios?: false }): Promise<QuickBaseResponseGetTable>; public async getTable({ tableId, appId, requestOptions, returnAxios }: QuickBaseRequestGetTable & { returnAxios: true }): Promise<AxiosResponse<QuickBaseResponseGetTable>>; public async getTable({ tableId, appId, requestOptions, returnAxios = false }: QuickBaseRequestGetTable): Promise<QuickBaseResponseGetTable | AxiosResponse<QuickBaseResponseGetTable>> { const results = await this.api<QuickBaseResponseGetTable>({ method: 'GET', url: `/tables/${tableId}`, params: { appId } }, requestOptions); return returnAxios ? results : results.data; } /** * Update a table * * Updates the main properties of a specific table. Any properties of the table that you do not specify in the request body will remain unchanged. * * [Quickbase Documentation](https://developer.quickbase.com/operation/updateTable) * * @param options Update a table method options object * @param options.tableId The unique identifier (dbid) of the table. * @param options.appId The unique identifier of an app * @param options.name The name for the table. * @param options.pluralRecordName The plural noun for records in the table. If this value is not passed the default value is 'Records'. * @param options.singleRecordName The singular noun for records in the table. If this value is not passed the default value is 'Record'. * @param options.description The description for the table. If this value is not passed the default value is blank. * @param options.requestOptions Override axios request configuration * @param options.returnAxios If `true`, the returned object will be the entire `AxiosResponse` object */ public async updateTable({ tableId, appId, requestOptions, returnAxios, ...body }: QuickBaseRequestUpdateTable & { returnAxios?: false }): Promise<QuickBaseResponseUpdateTable>; public async updateTable({ tableId, appId, requestOptions, returnAxios, ...body }: QuickBaseRequestUpdateTable & { returnAxios: true }): Promise<AxiosResponse<QuickBaseResponseUpdateTable>>; public async updateTable({ tableId, appId, requestOptions, returnAxios = false, ...body }: QuickBaseRequestUpdateTable): Promise<QuickBaseResponseUpdateTable | AxiosResponse<QuickBaseResponseUpdateTable>> { const results = await this.api<QuickBaseResponseUpdateTable>({ method: 'POST', url: `/tables/${tableId}`, data: body, params: { appId } }, requestOptions); return returnAxios ? results : results.data; } /** * Delete a table * * Deletes a specific table in an application, including all of the data within it. * * [Quickbase Documentation](https://developer.quickbase.com/operation/deleteTable) * * @param options Delete a table method options object * @param options.tableId The unique identifier (dbid) of the table. * @param options.appId The unique identifier of an app * @param options.requestOptions Override axios request configuration * @param options.returnAxios If `true`, the returned object will be the entire `AxiosResponse` object */ public async deleteTable({ tableId, appId, requestOptions, returnAxios }: QuickBaseRequestDeleteTable & { returnAxios?: false }): Promise<QuickBaseResponseDeleteTable>; public async deleteTable({ tableId, appId, requestOptions, returnAxios }: QuickBaseRequestDeleteTable & { returnAxios: true }): Promise<AxiosResponse<QuickBaseResponseDeleteTable>>; public async deleteTable({ tableId, appId, requestOptions, returnAxios = false }: QuickBaseRequestDeleteTable): Promise<QuickBaseResponseDeleteTable | AxiosResponse<QuickBaseResponseDeleteTable>> { const results = await this.api<QuickBaseResponseDeleteTable>({ method: 'DELETE', url: `/tables/${tableId}`, params: { appId } }, requestOptions); return returnAxios ? results : results.data; } /** * Get all relationships * * Get a list of all relationships, and their definitions, for a specific table. Details are provided for the child side of relationships within a given application. Limited details are returned for cross-application relationships. * * [Quickbase Documentation](https://developer.quickbase.com/operation/getRelationships) * * @param options Get all relationships method options object * @param options.childTableId The unique identifier (dbid) of the child table. * @param options.skip The number of relationships to skip. * @param options.requestOptions Override axios request configuration * @param options.returnAxios If `true`, the returned object will be the entire `AxiosResponse` object */ public async getRelationships({ childTableId, skip, requestOptions, returnAxios }: QuickBaseRequestGetRelationships & { returnAxios?: false }): Promise<QuickBaseResponseGetRelationships>; public async getRelationships({ childTableId, skip, requestOptions, returnAxios }: QuickBaseRequestGetRelationships & { returnAxios: true }): Promise<AxiosResponse<QuickBaseResponseGetRelationships>>; public async getRelationships({ childTableId, skip, requestOptions, returnAxios = false }: QuickBaseRequestGetRelationships): Promise<QuickBaseResponseGetRelationships | AxiosResponse<QuickBaseResponseGetRelationships>> { const results = await this.api<QuickBaseResponseGetRelationships>({ method: 'GET', url: `/tables/${childTableId}/relationships`, params: { skip } }, requestOptions); return returnAxios ? results : results.data; } /** * Create a relationship * * Creates a relationship in a table as well as lookup/summary fields. Relationships can only be created for tables within the same app. * * [Quickbase Documentation](https://developer.quickbase.com/operation/createRelationship) * * @param options Create a relationship method options object * @param options.childTableId The unique identifier (dbid) of the table. This will be the child table. * @param options.summaryFields[].summaryFid The field id to summarize. * @param options.summaryFields[].label The label for the summary field. * @param options.summaryFields[].accumulationType The accumulation type for the summary field. * @param options.summaryFields[].where The filter, using the Quickbase query language, which determines the records to return. * @param options.lookupFieldIds Array of field ids in the parent table that will become lookup fields in the child table. * @param options.parentTableId The parent table id for the relationship. * @param options.foreignKeyField.label The label for the foreign key field. * @param options.requestOptions Override axios request configuration * @param options.returnAxios If `true`, the returned object will be the entire `AxiosResponse` object */ public async createRelationship({ childTableId, requestOptions, returnAxios, ...body }: QuickBaseRequestCreateRelationship & { returnAxios?: false }): Promise<QuickBaseResponseCreateRelationship>; public async createRelationship({ childTableId, requestOptions, returnAxios, ...body }: QuickBaseRequestCreateRelationship & { returnAxios: true }): Promise<AxiosResponse<QuickBaseResponseCreateRelationship>>; public async createRelationship({ childTableId, requestOptions, returnAxios = false, ...body }: QuickBaseRequestCreateRelationship): Promise<QuickBaseResponseCreateRelationship | AxiosResponse<QuickBaseResponseCreateRelationship>> { const results = await this.api<QuickBaseResponseCreateRelationship>({ method: 'POST', url: `/tables/${childTableId}/relationship`, data: body, }, requestOptions); return returnAxios ? results : results.data; } /** * Update a relationship * * Use this endpoint to add lookup fields and summary fields to an existing relationship. Updating a relationship will not delete existing lookup/summary fields. * * [Quickbase Documentation](https://developer.quickbase.com/operation/updateRelationship) * * @param options Update a relationship method options object * @param options.childTableId The unique identifier (dbid) of the table. This will be the child table. * @param options.relationshipId The relationship id. This is the field id of the reference field on the child table. * @param options.summaryFields[].summaryFid The field id to summarize. * @param options.summaryFields[].label The label for the summary field. * @param options.summaryFields[].accumulationType The accumulation type for the summary field. * @param options.summaryFields[].where The filter, using the Quickbase query language, which determines the records to return. * @param options.lookupFieldIds An array of field ids on the parent table that will become lookup fields on the child table. * @param options.requestOptions Override axios request configuration * @param options.returnAxios If `true`, the returned object will be the entire `AxiosResponse` object */ public async updateRelationship({ childTableId, relationshipId, requestOptions, returnAxios, ...body }: QuickBaseRequestUpdateRelationship & { returnAxios?: false }): Promise<QuickBaseResponseUpdateRelationship>; public async updateRelationship({ childTableId, relationshipId, requestOptions, returnAxios, ...body }: QuickBaseRequestUpdateRelationship & { returnAxios: true }): Promise<AxiosResponse<QuickBaseResponseUpdateRelationship>>; public async updateRelationship({ childTableId, relationshipId, requestOptions, returnAxios = false, ...body }: QuickBaseRequestUpdateRelationship): Promise<QuickBaseResponseUpdateRelationship | AxiosResponse<QuickBaseResponseUpdateRelationship>> { const results = await this.api<QuickBaseResponseUpdateRelationship>({ method: 'POST', url: `/tables/${childTableId}/relationship/${relationshipId}`, data: body, }, requestOptions); return returnAxios ? results : results.data; } /** * Delete a relationship * * Use this endpoint to delete an entire relationship, including all lookup and summary fields. The reference field in the relationship will not be deleted. * * [Quickbase Documentation](https://developer.quickbase.com/operation/deleteRelationship) * * @param options Delete a relationship method options object * @param options.childTableId The unique identifier (dbid) of the table. This will be the child table. * @param options.relationshipId The relationship id. This is the field id of the reference field on the child table. * @param options.requestOptions Override axios request configuration * @param options.returnAxios If `true`, the returned object will be the entire `AxiosResponse` object */ public async deleteRelationship({ childTableId, relationshipId, requestOptions, returnAxios }: QuickBaseRequestDeleteRelationship & { returnAxios?: false }): Promise<QuickBaseResponseDeleteRelationship>; public async deleteRelationship({ childTableId, relationshipId, requestOptions, returnAxios }: QuickBaseRequestDeleteRelationship & { returnAxios: true }): Promise<AxiosResponse<QuickBaseResponseDeleteRelationship>>; public async deleteRelationship({ childTableId, relationshipId, requestOptions, returnAxios = false }: QuickBaseRequestDeleteRelationship): Promise<QuickBaseResponseDeleteRelationship | AxiosResponse<QuickBaseResponseDeleteRelationship>> { const results = await this.api<QuickBaseResponseDeleteRelationship>({ method: 'DELETE', url: `/tables/${childTableId}/relationship/${relationshipId}`, }, requestOptions); return returnAxios ? results : results.data; } /** * Get reports for a table * * Get the schema (properties) of all reports for a table. If the user running the API is an application administrator, the API will also return all personal reports with owner's user id. * * [Quickbase Documentation](https://developer.quickbase.com/operation/getTableReports) * * @param options Get reports for a table method options object * @param options.tableId The unique identifier of the table. * @param options.requestOptions Override axios request configuration * @param options.returnAxios If `true`, the returned object will be the entire `AxiosResponse` object */ public async getTableReports({ tableId, requestOptions, returnAxios }: QuickBaseRequestGetTableReports & { returnAxios?: false }): Promise<QuickBaseResponseGetTableReports>; public async getTableReports({ tableId, requestOptions, returnAxios }: QuickBaseRequestGetTableReports & { returnAxios: true }): Promise<AxiosResponse<QuickBaseResponseGetTableReports>>; public async getTableReports({ tableId, requestOptions, returnAxios = false }: QuickBaseRequestGetTableReports): Promise<QuickBaseResponseGetTableReports | AxiosResponse<QuickBaseResponseGetTableReports>> { const results = await this.api<QuickBaseResponseGetTableReports>({ method: 'GET', url: `/reports`, params: { tableId } }, requestOptions); return returnAxios ? results : results.data; } /** * Get a report * * Get the schema (properties) of an individual report. * * [Quickbase Documentation](https://developer.quickbase.com/operation/getReport) * * @param options Get a report method options object * @param options.reportId The identifier of the report, unique to the table. * @param options.tableId The unique identifier of table. * @param options.requestOptions Override axios request configuration * @param options.returnAxios If `true`, the returned object will be the entire `AxiosResponse` object */ public async getReport({ reportId, tableId, requestOptions, returnAxios }: QuickBaseRequestGetReport & { returnAxios?: false }): Promise<QuickBaseResponseGetReport>; public async getReport({ reportId, tableId, requestOptions, returnAxios }: QuickBaseRequestGetReport & { returnAxios: true }): Promise<AxiosResponse<QuickBaseResponseGetReport>>; public async getReport({ reportId, tableId, requestOptions, returnAxios = false }: QuickBaseRequestGetReport): Promise<QuickBaseResponseGetReport | AxiosResponse<QuickBaseResponseGetReport>> { const results = await this.api<QuickBaseResponseGetReport>({ method: 'GET', url: `/reports/${reportId}`, params: { tableId } }, requestOptions); return returnAxios ? results : results.data; } /** * Run a report * * Runs a report, based on an ID and returns the underlying data associated with it. The format of the data will vary based on the report type. Reports that focus on record-level data (table, calendar, etc.) return the individual records. Aggregate reports (summary, chart) will return the summarized information as configured in the report. UI-specific elements are not returned, such as totals, averages and visualizations. Returns data with intelligent pagination based on the approximate size of each record. The metadata object will include the necessary information to iterate over the response and gather more data. * * [Quickbase Documentation](https://developer.quickbase.com/operation/runReport) * * @param options Run a report method options object * @param options.reportId The identifier of the report, unique to the table. * @param options.tableId The identifier of the table for the report. * @param options.skip The number of records to skip. You can set this value when paginating through a set of results. * @param options.top The maximum number of records to return. You can override the default Quickbase pagination to get more or fewer results. If your requested value here exceeds the dynamic maximums, we will return a subset of results and the rest can be gathered in subsequent API calls. * @param options.requestOptions Override axios request configuration * @param options.returnAxios If `true`, the returned object will be the entire `AxiosResponse` object */ public async runReport({ reportId, tableId, skip, top, requestOptions, returnAxios }: QuickBaseRequestRunReport & { returnAxios?: false }): Promise<QuickBaseResponseRunReport>; public async runReport({ reportId, tableId, skip, top, requestOptions, returnAxios }: QuickBaseRequestRunReport & { returnAxios: true }): Promise<AxiosResponse<QuickBaseResponseRunReport>>; public async runReport({ reportId, tableId, skip, top, requestOptions, returnAxios = false }: QuickBaseRequestRunReport): Promise<QuickBaseResponseRunReport | AxiosResponse<QuickBaseResponseRunReport>> { const results = await this.api<QuickBaseResponseRunReport>({ method: 'POST', url: `/reports/${reportId}/run`, params: { tableId, skip, top } }, requestOptions); return returnAxios ? results : results.data; } /** * Get fields for a table * * Gets the properties for all fields in a specific table. The properties for each field are the same as in Get field. * * [Quickbase Documentation](https://developer.quickbase.com/operation/getFields) * * @param options Get fields for a table method options object * @param options.tableId The unique identifier (dbid) of the table. * @param options.includeFieldPerms Set to 'true' if you'd like to get back the custom permissions for the field(s). * @param options.requestOptions Override axios request configuration * @param options.returnAxios If `true`, the returned object will be the entire `AxiosResponse` object */ public async getFields({ tableId, includeFieldPerms, requestOptions, returnAxios }: QuickBaseRequestGetFields & { returnAxios?: false }): Promise<QuickBaseResponseGetFields>; public async getFields({ tableId, includeFieldPerms, requestOptions, returnAxios }: QuickBaseRequestGetFields & { returnAxios: true }): Promise<AxiosResponse<QuickBaseResponseGetFields>>; public async getFields({ tableId, includeFieldPerms, requestOptions, returnAxios = false }: QuickBaseRequestGetFields): Promise<QuickBaseResponseGetFields | AxiosResponse<QuickBaseResponseGetFields>> { const results = await this.api<QuickBaseResponseGetFields>({ method: 'GET', url: `/fields`, params: { tableId, includeFieldPerms } }, requestOptions); return returnAxios ? results : results.data; } /** * Create a field * * Creates a field within a table, including the custom permissions of that field. * * [Quickbase Documentation](https://developer.quickbase.com/operation/createField) * * @param options Create a field method options object * @param options.tableId The unique identifier of the table. * @param options.audited Indicates if the field is being tracked as part of Quickbase Audit Logs. You can only set this property to "true" if the app has audit logs enabled. See Enable data change logs under [Quickbase Audit Logs](https://help.quickbase.com/user-assistance/audit_logs.html). Defaults to false. * @param options.fieldHelp The configured help text shown to users within the product. * @param options.bold Indicates if the field is configured to display in bold in the product. Defaults to false. * @param options.properties.comments The comments entered on the field properties by an administrator. * @param options.properties.doesTotal Whether this field totals in reports within the product. * @param options.properties.autoSave Whether the link field will auto save. * @param options.properties.defaultValueLuid Default user id value. * @param options.properties.useI18NFormat Whether phone numbers should be in E.164 standard international format * @param options.properties.maxVersions The maximum number of versions configured for a file attachment. * @param options.properties.format The format to display time. * @param options.properties.carryChoices Whether the field should carry its multiple choice fields when copied. * @param options.properties.maxLength The maximum number of characters allowed for entry in Quickbase for this field. * @param options.properties.linkText The configured text value that replaces the URL that users see within the product. * @param options.properties.parentFieldId The id of the parent composite field, when applicable. * @param options.properties.displayTimezone Indicates whether to display the timezone within the product. * @param options.properties.allowNewChoices Indicates if users can add new choices to a selection list. * @param options.properties.defaultToday Indicates if the field value is defaulted today for new records. * @param options.properties.units The units label. * @param options.properties.openTargetIn Indicates which target the URL should open in when a user clicks it within the product. * @param options.properties.sourceFieldId The id of the source field. * @param options.properties.doesAverage Whether this field averages in reports within the product. * @param options.properties.formula The formula of the field as configured in Quickbase. * @param options.properties.decimalPlaces The number of decimal places displayed in the product for this field. * @param options.properties.defaultCountryCode Controls the default country shown on international phone widgets on forms. Country code should be entered in the ISO 3166-1 alpha-2 format. * @param options.properties.displayMonth How to display months. * @param options.properties.seeVersions Indicates if the user can see other versions, aside from the most recent, of a file attachment within the product. * @param options.properties.numLines The number of lines shown in Quickbase for this text field. * @param options.properties.defaultKind The user default type. * @param options.properties.displayEmail How the email is displayed. * @param options.properties.coverText An alternate user friendly text that can be used to display a link in the browser. * @param options.properties.currencySymbol The current symbol used when displaying field values within the product. * @param options.properties.targetFieldId The id of the target field. * @param options.properties.displayUser The configured option for how users display within the product. * @param options.properties.blankIsZero Whether a blank value is treated the same as 0 in calculations within the product. * @param options.properties.exact Whether an exact match is required for a report link. * @param options.properties.defaultDomain Default email domain. * @param options.properties.defaultValue The default value configured for a field when a new record is added. * @param options.properties.abbreviate Don't show the URL protocol when showing the URL. * @param options.properties.numberFormat The format used for displaying numeric values in the product (decimal, separators, digit group). * @param options.properties.targetTableName The field's target table name. * @param options.properties.appearsAs The link text, if empty, the url will be used as link text. * @param options.properties.width The field's html input width in the product. * @param options.properties.currencyFormat The currency format used when displaying field values within the product. * @param options.properties.displayDayOfWeek Indicates whether to display the day of the week within the product. * @param options.properties.commaStart The number of digits before commas display in the product, when applicable. * @param options.properties.choices An array of entries that exist for a field that offers choices to the user. Note that these choices refer to the valid values of any records added in the future. You are allowed to remove values from the list of choices even if there are existing records with those values in this field. They will be displayed in red when users look at the data in the browser but there is no other effect. While updating a field with this property, the old choices are removed and replaced by the new choices. * @param options.properties.targetTableId The id of the target table. * @param options.properties.displayRelative Whether to display time as relative. * @param options.properties.compositeFields An array of the fields that make up a composite field (e.g., address). * @param options.properties.displayCheckboxAsText Indicates whether the checkbox values will be shown as text in reports. * @param options.properties.displayTime Indicates whether to display the time, in addition to the date. * @param options.properties.versionMode Version modes for files. Keep all versions vs keep last version. * @param options.properties.snapFieldId The id of the field that is used to snapshot values from, when applicable. * @param options.properties.hours24 Indicates whether or not to display time in the 24-hour format within the product. * @param options.properties.sortAlpha Whether to sort alphabetically, default sort is by record ID. * @param options.properties.sortAsGiven Indicates if the listed entries sort as entered vs alphabetically. * @param options.properties.hasExtension Whether this field has a phone extension. * @param options.properties.useNewWindow Indicates if the file should open a new window when a user clicks it within the product. * @param options.properties.appendOnly Whether this field is append only. * @param options.properties.displayAsLink Indicates if a field that is part of the relationship should be shown as a hyperlink to the parent record within the product. * @param options.appearsByDefault Indicates if the field is marked as a default in reports. Defaults to true. * @param options.fieldType The [field types](https://help.quickbase.com/user-assistance/field_types.html), click on any of the field type links for more info. * @param options.permissions[].role The role associated with a given permission for the field * @param options.permissions[].permissionType The permission given to the role for this field * @param options.permissions[].roleId The Id of the given role * @param options.addToForms Whether the field you are adding should appear on forms. Defaults to false. * @param options.label The label (name) of the field. * @param options.findEnabled Indicates if the field is marked as searchable. Defaults to true. * @param options.noWrap Indicates if the field is configured to not wrap when displayed in the product. Defaults to false. * @param options.requestOptions Override axios request configuration * @param options.returnAxios If `true`, the returned object will be the entire `AxiosResponse` object */ public async createField({ tableId, requestOptions, returnAxios, ...body }: QuickBaseRequestCreateField & { returnAxios?: false }):