AdamKeever1
5 years agoQrew Commander
Re: RESTful API Header
Thanks for looking at this when you have time. I just defined two separate constants xmlHttp1 & xmlHttp2. The issue is trying to use the ticket outside of the function. I added a check before trying to pass to the next script block and the ticket is undefined outside of the function; the query executes, but does not have authorization:
------------------------------
Adam Keever
------------------------------
<!---------------GET_TEMPORARY_TOKEN---------------------->
<script>
var ticket;
var tempAuth;
var headers = {
'QB-Realm-Hostname': '[MY REALM]',
'QB-App-Token': '[MY APP TOKEN]',
'Content-Type': 'application/json'
}
const xmlHttp1 = new XMLHttpRequest();
xmlHttp1.open('GET', 'https://api.quickbase.com/v1/auth/temporary/[MY TABLE ID]', true);
for (const key in headers) {
xmlHttp1.setRequestHeader(key, headers[key]);
}
xmlHttp1.onreadystatechange = function() {
if (xmlHttp1.readyState === XMLHttpRequest.DONE) {
console.log(xmlHttp1.responseText);
document.getElementById("AUTH#").innerHTML = xmlHttp1.responseText;
ticket = JSON.parse(xmlHttp1.responseText);
document.getElementById("VAR#").innerHTML = ticket.temporaryAuthorization;
}
};
xmlHttp1.withCredentials = true;
xmlHttp1.send();
ticket1 = xmlHttp1.onreadystatechange("xmlHttp1.responseText");
console.log(xmlHttp1.responseText);
tempAuth = "QB-TEMP-TOKEN " + ticket1;
document.getElementById("CHK#").innerHTML = tempAuth;
</script>
------------------------------
Adam Keever
------------------------------