2

I am trying to pull products from my BigCommerce store through jquery Ajax, what i am doing is by passing username and token key:

var key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
var auth = 'Basic ' + Base64.encode('admin:'+key);
var url = 'https://store-xxxxxxxxx.mybigcommerce.com/api/v2/products.json';

    $.ajax({
        url : url,
        method : 'GET',
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        async: false,
        crossDomain: true,
        beforeSend : function(req) {
            req.setRequestHeader('Authorization', auth);
        },
        success: function(result) {
            alert('done');
            console.log(result);
        },
        error: function (request, textStatus, errorThrown) {
            console.log(request.responseText);
            console.log(textStatus);
            console.log(errorThrown);
        }
    });

But every time i get "Failure" message.

Imran Khan
  • 2,373
  • 2
  • 22
  • 35
  • Are you calling from a HTTPS site? `API authentication is handled with HTTP Basic access authentication. Connections to the API must be made with a secure HTTPS connection.` Because code looks fine to me – Justinas Kanguras Dec 16 '13 at 08:32
  • i have tried with both ways, but no success, can you clarify it more? – Imran Khan Dec 16 '13 at 09:36
  • http://stackoverflow.com/questions/231478/ajax-subdomains-and-ssl so I suggest you to call a server side script (on your server) using ajax that will handle those https request to BigCommerce. I'm not 100% if that is the problem. – Justinas Kanguras Dec 16 '13 at 09:56

0 Answers0