Using jQuery to interact with API

I'm relatively new to Campaign Monitor. Signed up my first client through the white label service just today in fact. Now they're interested in taking the reports a set further. They'd like to have the reports viewable on their own domain.

I've been trying to use the jQuery method .ajax but so far it's been unsuccessful. Is it possible to access the report api via jQuery? If yes, why isn't my code below working. It just fails silently, not event the error callback shows up...

$.ajax({
  url: 'http://api.createsend.com/api/v3/clients/secretclientcodehere.json',
 
 
  dataType: 'jsonp',
  dataFilter: function(data, type){
         alert("data is: " + data);
     },
  success: function(data) {
    $('.result').html(data);
    alert('Load was performed.');
    alert(data);
  },
  error: function(xht, type, details){
      alert('error ' + details);
  },
  complete: function(xht, textStatus){
      alert(xht);
      alert(textStatus);}
})%3

The %3 at the end is suppose to be two curly closing br

jjosephs, 5 years ago

The %3 at the end is suppose to be two curly closing braces followed by a closing parentheses and a semi-colon. Forum kept stripping it out for som strange reason.

jamesd jamesd, 5 years ago

Hey there,

We actually don't support responses using JSONP, which it appears you are trying to use to get around the same origin policy.

We deliberately chose not to support JSONP. The simple reason for this is that we do not have any "public" API methods available which do not require an API key to be used, and we didn't want to encourage people to start writing JavaScript which included their API in clear text.

In your case, you probably want to make your calls to the Campaign Monitor API on your server, rather than directly from the browser.

Join 200,000 companies around the world that use Campaign Monitor to run email marketing campaigns that deliver results for their business.

Get started for free
1-888-533-8098