Vathson Posted September 1, 2021 Share Posted September 1, 2021 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) } }); .. Beyondspace 1 Link to comment
Beyondspace Posted November 11, 2021 Share Posted November 11, 2021 On 9/1/2021 at 7:51 PM, Vathson said: 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) } }); .. Did you check user name and password correctly? BeyondSpace - Squarespace Website Developer 🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox) 🗓️ Delivery Date Picker (Squarespace Date picker form field) 💫 Gallery block 7.1 workaround 🥳 Sparkplugin Customisations Browsers (Browse +100 Spark plugin customisations) 🥳 Elfsight Template Browsers (Browse +1000 Elfsight widget Templates) If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you! Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment