Is there any API for getting App Token & DBIDS w.r.t to table name?

  • 0
  • 1
  • Question
  • Updated 1 year ago
  • In Progress
Photo of Rohit Agarwal

Rohit Agarwal

  • 552 Points 500 badge 2x thumb

Posted 1 year ago

  • 0
  • 1
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 26,522 Points 20k badge 2x thumb
Application Tokens are associated with Applications not individual tables. Additionally, there can be several Application Tokens associated with an Application. Given these two observations it isn't clear what your original question is asking or what you are trying to accomplish.

In any case when you are trying to automate some task across your entire account it can be problematic using the API because there is often no common Application Token to use within your script (unless you manually set this up). In these cases you can still write the script but you have to use non-API methods. This may seem unusual if it is your first exposure to the technique but you can GET or POST to any QuickBase endopoint URL using AJAX methods.
Photo of Rohit Agarwal

Rohit Agarwal

  • 552 Points 500 badge 2x thumb
You didn't get my question. 
API that gives me DBID w.r.t to table name means I pass table name as the parameter and I get the DBID.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 26,272 Points 20k badge 2x thumb
So where does the part about "App Token" fit into your reformulated question?
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 26,522 Points 20k badge 2x thumb
> I pass table name as the parameter and I get the DBID.

Like this:

var name = "250 Bottles of Beer on the Form";

$.get("main?act=API_GrantedDBs")
  .then(function(xml) {
    var dbid = $("dbname", xml).filter(function() {
      return $(this).text() === name;
    }).next("dbid").text();
    console.log(dbid);
  })

//output
bj4vxvurn
(Edited)
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 26,522 Points 20k badge 2x thumb
Or this version which employs Async / Await:

(function(){
  async function getDBID(name) {
    var xml = await Promise.resolve(
      $.get("main?act=API_GrantedDBs")
    );
    var dbid = $("dbname", xml).filter(function() {
      return $(this).text() === name;
    }).next("dbid").text();
    return dbid;
  }
  var name = "250 Bottles of Beer on the Form";
  getDBID(name).then(function(dbid) {
    console.log(dbid, name)
  });
})();
//output:
//bj4vxvurn 250 Bottles of Beer on the Form
(Edited)
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 26,522 Points 20k badge 2x thumb
No. You can only use it within JavaScript.
Photo of Rohit Agarwal

Rohit Agarwal

  • 552 Points 500 badge 2x thumb
I have a formula URL field with formula 
- URLRoot() & "db/" & Dbid() & "?a=dbpage&pagename=xxx.html&pid=" &[record-id]

when I land to xxx.html 
I won't be able to access gReqAppDBID global variable. Any comments?
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 26,522 Points 20k badge 2x thumb
I assumed you were injecting your code into a QuickBase authored page in which case the global is available. However, code pages are completely empty and consist of only the code you explicitly include - so you don't have access to any QuickBase globals nor any libraries such as jQuery unless you load them yourself into the code page.
(Edited)
Photo of Rohit Agarwal

Rohit Agarwal

  • 552 Points 500 badge 2x thumb
Alright, 
Any solution you will suggest in order to access Quickbase Globals in the code page.
Photo of Rohit Agarwal

Rohit Agarwal

  • 552 Points 500 badge 2x thumb
I used 

"javascript:$.getScript('https://xxx.com/db/' + gReqAppDBID + '?act=dbpage&pagename=xxx.js');"

in formula field than in my xxx.js 
I did window.location.href = 'xx.html'


But it's not working.