What Exactly is the ""Be The API"" Technique?
What Exactly is the "Be The API" Technique?
Every now and then people ask if an API method exists to do some particular task. Occasionally, there is no method in the official API documentation that performs the desired task:
Welcome to the QuickBase HTTP API Reference
http://www.quickbase.com/api-guide/index.html
In other cases native QuickBase has a feature or displays information that you would like to programmatically access (ie using script) rather than work the user interface manually
In such cases you can (1) give up and abandon all hope that you will ever see your feature implemented through an API method or (2) create the API yourself using the Be The API technique. Let me demonstrate the technique with three different examples:
Example 1: getRecordPickerFields(dbidTable)
There is no API method that will return the fids of the record picker fields. The only place this information is available is on the following page:
dbidTable?a=KeyProps
This function will return an array of fids (of length 3) for the record picker fields for the specified table dbid.
Example 2: getApplicationTokens(dbidApplication)
There is no API method that will return all the application tokens for an application. The only place this information is available is on the following page:
dbidApplication?a=GetAppDevKey
This function will return an array of application tokens for the specified application dbid.
Example 3: getAPICounts(accountid)
There is no API method that will return the number of API calls for each of the last thirty days. The only place this information is available is through a chart visible when you click on the "View API usage" link on the following page:
main?a=AccountSummary&accountid=102959
The code for each of these functions (little more than a dozen lines of code in each case) is listed in the following pastie:
Pastie Database
https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=388
Notes:
(1) Each function returns a jQuery promise which when resolved provides the requested information as an argument
(2) Each function was attached to the jQuery object. This isn't necessary but rather than creating three new global methods I just attached them to the $ object
(3) The first two functions getRecordPickerFields and getApplicationTokens extract the results out of the html returns by an AJAX call using standard jQuery DOM selection methods. The third function getAPICounts actually loads the AccountSummary page into a hidden <iframe> and once the <iframe> loads access the JavaScript object that contains array of API counts from which the chart is generated.
(4) You can test each of these code fragments by pasting them into the JavaScript console and supplying an appropriate value for the parameters dbidTable, dbidApplication, or accountid.
(5) This technique is perfectly general - any scrap of information that exists in a QuickBase page (eg text, DOM nodes, JavaScript variables etc) can be returned through a promise using this method. Likewise any action native QuickBase performs can be ported into a custom API which can be called at will through script. The procedure is the same as these three examples demonstrate and will probably only require about a dozen lines of code.
(6) See also: https://quickbase-community.intuit.com/questions/175577