Forum Discussion

WilliamMarrone's avatar
WilliamMarrone
Qrew Cadet
8 years ago

Having trouble getting an API call to fire.

Hello I am a new Quickbase user having a bit of trouble writing a script to return a small sample of data. Below is my code,

var url = "domain";
url += "/db/";
url += "bm9rx6w83"; 
url += "?a=API_DoQuery";

var request = "<qdbapi>";
request += "<apptoken>tvy5zcdaqafyfxp43vhd78gyys</apptoken>";
request += "<query>{'20'.GT.'1000'}</query>";
request += "<clist>a</clist>";
request += "<options>sortorder-D</options>";
request += "</qdbapi>";

$.ajax({
type: "POST",
contentType: "text/xml",
async: false,
url: url,
data: request,
dataType: "xml",
processData: false,
success: function (response) {

var xml = $(response);
if(xml.find("qdbapi").find('errcode').text() == "0"){

processRecords(xml);

}
else
{
console.log("Quickbase returned an error.");
console.log(response);
}
     },
error.function (response) {
console.log("Quickbase Returned an error");
console.log(response);
}
});

function processRecords(xml)
{


xml.find('qdbapi').find('record').each(function(index){
console.log("Name: " + $(this).find("name").text());
console.log("Tuition: " + $(this).find("tuition").text());
console.log("Major: " +  $(this).find("major").text());
});
}

I replaced the domain name obviously so that is not the problem but I cannot get a post message to show up with the data. It is only three records in a student table. The only thing I get posted back when I run off MY Iframe button is 
 XHR finished loading: GET "https://domain/db/bm9rv78gs?a=dbpage&pagename=GetStudents.js&_=1512409558232"....

Anyone have any ideas? I am still pretty new with it so I could just be a gaf on my side.
  • Try this by pasting into the console (don't waste your time pasting into a code page):

    (function() {
      var dbid = "<your application dbid>";
      var dbidTable = "bm9rx6w83";
      var apptoken = "tvy5zcdaqafyfxp43vhd78gyys";
      $.ajaxSetup({data: {apptoken: apptoken}});
      $.post(dbidTable, {
        act: "API_DoQuery",
        query: "{20.GT.1000}",
        clist: "a",
        options: "sortorder-D"
      }).then(function(xml) {
        console.dirxml(xml);
        var name, tuition, major;
        $("record", xml).each(function() {
          name = $("name", this).text();
          tuition = $("tuition", this).text();
          major = $("major", this).text();
          console.log(name, tuition, major);
        });
      });
    })();
  • That correctly returned the three records, is there any way to attach this to a Button to run from a homepage?
    • _anomDiebolt_'s avatar
      _anomDiebolt_
      Qrew Elite
      Embed a report on the homepage and within the report create a button field. QuickBase makes it difficult to attach a script to a lone button within the button bar.
    • WilliamMarrone's avatar
      WilliamMarrone
      Qrew Cadet
      Thanks a lot is there any way to return the tuition as a number or convert it to summarize?
    • _anomDiebolt_'s avatar
      _anomDiebolt_
      Qrew Elite
      > ... return the tuition as a number

      tuition = parseFloat($("tuition", this).text());

      > ... or convert it to summarize

      Based on the names of your other fields (name and major) I would have assumed the record represented a person in the aggregate and that tuition would represent the current semester's tuition. If you need to summarize tuition you need to further describe your records and any child records along with how you want tuition to summarize (total, average, harmonic mean?)