Forum Discussion

MyoshiaBoykin-A's avatar
MyoshiaBoykin-A
Qrew Trainee
4 years ago

Displaying reports on web pages using Javascript

I will start by admitting that I am not a "real" developer :).  I have been working with the new RESTful API (thanks to Harrison) and I've been able to get a Success (200) within the QB API Portal; however, I can figure out how to embed the Javascript into a plain HTML page to render the report.  I can worry about formatting and CSS later, I presume, but I just want to be able to test it and see the data first.  I am just using ATOM to create the index.html page and I'm using XAMMP for the localhost.  Can someone share with me how I would format the html to embed the following javascript code:


var headers = {
'QB-Realm-Hostname': 'xxxxxxxxxx',
'User-Agent': '{User-Agent}',
'Authorization': 'QB-USER-TOKEN xxxxx_xxxx_xxxxxxxxxxxxxxxxx',
'Content-Type': 'application/json'
}


const xmlHttp = new XMLHttpRequest();
xmlHttp.open('POST', 'https://api.quickbase.com/v1/reports/10/run?tableId=xxxxxxxx&skip={skip}&top={top}', true);
for (const key in headers) {
xmlHttp.setRequestHeader(key, headers[key]);
}
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState === XMLHttpRequest.DONE) {
console.log(xmlHttp.responseText);
}
};

xmlHttp.send();

------------------------------
Myoshia Boykin-Anderson
------------------------------

2 Replies

  • hhersch's avatar
    hhersch
    Qrew Captain
    Hi Myoshia! Thanks for the shout-out! First thing is, you don't want to store a usertoken in JavaScript. That isn't a security best practice. We provide a temp authorization endpoint to help you with that. Take a look at this sample app we created that illustrates both a database page and temporary tokens and see if it helps.

    ------------------------------
    Harrison Hersch
    ------------------------------
    • MyoshiaBoykin-A's avatar
      MyoshiaBoykin-A
      Qrew Trainee
      Thanks Harrison - I will use the temp auth endpoint instead.  So once I fetch a temp token, how do I get the report to display on my web page?

      ------------------------------
      Myoshia Boykin-Anderson
      ------------------------------