Forum Discussion

_anomDiebolt_'s avatar
_anomDiebolt_
Qrew Elite
10 years ago

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 dbidTabledbidApplication, 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

  • I just needed this function for some client work so I added this example:

    Example 4: getExpandedURL(dbid, qid)


    There is no published API method that will return the individual query parameters as an object given the dbid and qid. The only place this information is available is on the following page:

    dbidTable?a=JBI_GenExpandedURL&qid=1

    This function will return an object of all the constituent query parameters associated with a query given a dbid and qid.

    Pastie Database
    https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=407



    • _anomDiebolt_'s avatar
      _anomDiebolt_
      Qrew Elite
      Someone just liked my answer. But there is another reason to use the "Be The API" technique that was not mentioned in the post. If you want your script to iterate over all applications, tables, reports, queries etc there probably will not be a common API token setup so you can't use the API at all. You can however call all the other non-API methods to accomplish the same goal. This is especially important when asking another user to run a script from their account.

      ASK: Please Give Me Your Formulas
      https://community.quickbase.com/quickbase/topics/formula-parser-in-javascript#reply_18555784