Skip to main content
Question

Having trouble getting an API call to fire.

  • December 4, 2017
  • 0 replies
  • 29 views

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.
This topic has been closed for replies.

  • Registered
  • December 4, 2017
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);
    });
  });
})();

  • Author
  • Registered
  • December 4, 2017
That correctly returned the three records, is there any way to attach this to a Button to run from a homepage?