I'm creating a GET request from my square space site to Big commerce using ajax API call. But facing 401 unauthorized error.
I've attached my code I'm using right now - hope someone can help me out of this problem.
const username = "username";
const password = "password";
function make_base_auth(user, password) {
var tok = user + ':' + password;
var hash = btoa(tok);
return "Basic " + hash;
}
$.ajax({
url: "https://api.bigcommerce.com/stores/{store-hash}/v3/catalog/products",
async: true,
crossDomain: true,
beforeSend: function(xhr) {
xhr.setRequestHeader('Authorization', make_base_auth(username, password));
},
headers: {
"X-Auth-Client": "secret-key",
"X-Auth-Token": "token",
"Content-Type": "application/json",
"cache-control": "no-cache",
},
type: "GET",
dataType: "jsonp",
success: function(data) {
console.log(data)
}
});
..