Access Record data from an html page via API call

  • 0
  • 1
  • Question
  • Updated 5 months ago
  • Answered
  • (Edited)
I have had a hard time getting accustomed to working with API calls from outside of Quick Base and since I have limited experience with XML. Finally after struggling quite a bit I have come up with a (seemingly) decent method for getting/accessing record data from an API call in an HTML page.

I will post the code below and please provide any feedback for this method, I am still early using Quick base API calls. This method uses the option to return the record data as a 2-dimensional array that can be accessed with "qdb_data[x][x]" where the "x" is the index selector. You can easily check the number of returned records by looking at "qdb_data.length"


<head>
<script lang="javascript" src="yourdomain/db/
yourtable?a=API_GenResultsTable&query={'field id'.operator.matchvalue}&jsa=1&apptoken=[yourtoken]">
</script>
<script>
function displayData(){
alert(qdb_data[x][x]);
}</script>
</head>

Curious about the security of having the API info and app token within the client-side code. Obviously a QB code page is fairly secure compared to a remote code page but still curious about it. 

Thanks everyone.
Photo of David Brogdon

David Brogdon

  • 1,222 Points 1k badge 2x thumb

Posted 5 months ago

  • 0
  • 1
Photo of David Brogdon

David Brogdon

  • 1,222 Points 1k badge 2x thumb
Just figured I would add code for how to pull values into the code page from a URL button within QB. Just replace "rid" with the name of your parameter name.

<script>
function getUrlParameters() {
    var params = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
        params[key] = value;
    });
    return params;   }
function doCode(){
var recordID=getUrlParameters() ["rid"]; 
alert(recordID); 
 }
</script>
(Edited)
Photo of David Brogdon

David Brogdon

  • 1,222 Points 1k badge 2x thumb
This is one way to make further API calls after processing data on code page -->

var request = new XMLHttpRequest();
request.open('POST', 'https://yourdomain.quickbase.com/db/yourtable?a=API_yourAPIcall&apptoken=yourapptoken', true);
request.onload = function () {
  alert("record added");
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,074 Points 20k badge 2x thumb
No need for a custom function as all modern browsers now support URLSearchParams
var urlParams = new URLSearchParams(window.location.search);
var recordID = urlParams.get("rid"));
alert(recordID); 
https://caniuse.com/#feat=urlsearchparams