JavaScript Access MailChimp API 3.0 (GET)

I'm trying to make a GET request through jQuery to the Mailchimp API. It seems though my custom header is not correctly set as I get a Your request did not include an API key. error.

It works fine if I make the request using curl on my Ubuntu machine:

curl --header "Authorization: apikey 709XXXXXXXXXXXXXXXXXXXXXXXXXXXXX-us11" https://us11.api.mailchimp.com/3.0/campaigns

Here's my code:

$.ajax({
    type: 'GET',
    url: 'https://us11.api.mailchimp.com/3.0/campaigns',
    crossDomain: true,
    dataType: 'jsonp',
    contentType: "application/json; charset=utf-8",
    headers: {
        'Authorization': 'apikey 709XXXXXXXXXXXXXXXXXXXXXXXXXXXXX-us11'
    }
}).done(function (response) {
    console.log(response); // verbose
});

I even tried adding this above:

$.ajaxSetup({
    headers: { 'Authorization': 'apikey 709XXXXXXXXXXXXXXXXXXXXXXXXXXXXX-us11' }
});
Answer:1

You need to add the key via Basic Auth like and as far I am aware off, You can't query it from front-end, it must be on the back-end.

Find an example in NodeJS:

headers: {
    'Authorization': 'Basic ' + new Buffer(`anything:${MailChimpKey}`).toString('base64');
}
Answer:2

I see a strange behavior when redirecting to a URL with Backbone router. If I try to redirect to: //myserver/component_issues/index?id=org.codehaus.sonar:sonarqube ... everything is fine, but I get ...

I see a strange behavior when redirecting to a URL with Backbone router. If I try to redirect to: //myserver/component_issues/index?id=org.codehaus.sonar:sonarqube ... everything is fine, but I get ...

I want to return data from a Service function and inject it into a controller via the routeProvider, but only once the data has been fully loaded. app.js: .when('/sources', { templateUrl:...

I want to return data from a Service function and inject it into a controller via the routeProvider, but only once the data has been fully loaded. app.js: .when('/sources', { templateUrl:...

  1. angular return data from subscribe
  2. angular return data from observable
  3. angular return data from dialog
  4. angular return data from service to component
  5. angular return data from modal
  6. angular return data from service
  7. angular return data from component
  8. angular return data from promise
  9. angular return data
  10. angular return data from post
  11. angular return data from api
  12. angular return data from function
  13. angular return data from http
  14. angular return data from http call
  15. angular material return data from dialog
  16. angular 6 return data from service
  17. angular 6 return data from subscribe
  18. angular httpclient return data
  19. angular 7 return data from subscribe
  20. angular 6 return data from observable

The code snippet for the jQuery function looks like: function addMessage() { if (textval != "") { text_string='<div class="alert-box round"><p class="text-left">' + userName + ...

The code snippet for the jQuery function looks like: function addMessage() { if (textval != "") { text_string='<div class="alert-box round"><p class="text-left">' + userName + ...

Such as: var foo = function (a, b) { return a + b; }; var bar = function (a, b) { return a * b; }; var fn = _.compose([foo, bar]); How to understand the fn?

Such as: var foo = function (a, b) { return a + b; }; var bar = function (a, b) { return a * b; }; var fn = _.compose([foo, bar]); How to understand the fn?