Has anyone successfully set up an $http post to add a subscriber to a Mailchimp list in the v3.0 API? I’ve written the below code (and have tried various different suggestions that I have read on the forums). The problem I am getting is XMLHttpRequest cannot load http://usXX.api.mailchimp.com/3.0/lists/XXXX/members. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:8100’ is therefore not allowed access. The response had HTTP status code 501.
$scope.saveSubscribe = function () {
var url = 'http://usXX.api.mailchimp.com/3.0/lists/XXXXX/members';
var subscription = { "email_type": "john@smith.com", "status": "subscribed", "merge_fields": {"FNAME": "John", "LNAME": "Smith"}};
var req = {
method: 'POST',
url: url,
headers: {
'Content-Type': 'application/json',
'Auth-Token': "username APIKEY",
'Authorization': "username APIKEY",
'Authorized': "username APIKEY"
},
data: subscription
}
$http(req).
success(function(data, status, headers, config) {
console.log('[Debug] success', data);
alert('Clever boy');
}).
error(function(data, status, headers, config) {
console.log('[Debug] failed', status, config, headers, data);
alert('Failure!');
});
}