javascriptchargify

Chargify Problems Using API: "Not allowed access"


I am trying to retrieve information from my Chargify test account but I am getting two errors: 401 (which disappears after "authenticating") and then I get 404 which I do not understand since it works on my browser after authenticating.

I am not really good with web coding so I am sure that is the problem. What i am using to try and get the data from the URL is this:

 $.ajax({
        type: "GET",
        url: "https://testingtests.chargify.com/customers.json",
        dataType: "json",
        beforeSend: function (xhr) {
            xhr.setRequestHeader('Authorization', make_base_auth("someusername", "somepassword"));
        },
        success: function (response) {
            alert(response.d);
        },
        failure: function (response) {
            alert(response.d);
        },
    })

    function make_base_auth(user, password) {
        var tok = user + ':' + password;
        var hash = btoa(tok);
        return 'Basic ' + hash;
    }

EDIT: I just read that the problem seems to be that one cannot do cross domain access and that I would have to use cURL but I have not found anything on how to use it.


Solution

  • Chargify doesn't support CORS currently (no direct cross domain access), so you'll need to use a proxy (server code) if you want to be able to access the API (through the proxy) via JavaScript.

    The proxy would be where you would use cURL (or any of the existing API wrapping libraries), then provide an interface to your client side code to get that to work.