Mailchimp API v3.0

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!');    
    });
}
1 Like

Experienced the same issue.

Where can I find integration code with Ionic and MailchimAPI

Add subscribers, send email after subscription, etc

Thanks,
Eyal

For those who come across this issue, I’ve found a good solution: https://github.com/keithio/angular-mailchimp
It works with ionic#1.3.1

I had to make some adjustments I hope they accept them, if they don’t you need to apply this fix: https://github.com/keithio/angular-mailchimp/pull/16 to make it work with cordova.