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, video lightbox and much more) 🗓️ Delivery Date Picker (Squarespace Date picker form field) 💫 Gallery block 7.1 workaround 🥳 No-code customisations for Squarespace (+100 Spark plugin customisations) 🥳 Freemium Squarespace Widget Templates (+1000 Elfsight 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