I'm making an API request using this code:
function httpGet(url){
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
console.log(this.status)
if (this.readyState == 4 && this.status == 200) {
console.log("Got names")
getNamesFromJSONArray(request.responseText);
};
};
request.open("GET", url, true);
request.setRequestHeader("Authorization", "Basic (API key goes here)");
request.setRequestHeader("Accept-Encoding", "gzip");
request.send();
}
It worked just the other day but now it fails, telling me:
Failed to load resource: Preflight response is not successful
and
XMLHttpRequest cannot load https://api.insight.ly/v2.1/contacts. Preflight response is not successful
Also, "Got names" is never printed.
Why would this code break when it worked just the other day? Is it a problem on the API end or mine?
UPDATE! I found this on the api website. What would be the simplest way to implement this? I currently have no backend and don't need one for anything besides this. I understand the issue is because they don't want my API in client-readable Javascript, which makes sense. Could I log in to the API some other way, perhaps by a user's email and password?