I'd like to use the Mailchimp Node.js API in my Parse Cloud Hosting app to subscribe a user to a mailing list. Parse doesn't support NPM but, given that the Mailchimp API has no dependencies, I thought I'd be able to copy the code into my project. However, the Mailchimp API uses the "https" module which Parse doesn't support.
Does anyone know of a way around this?
Mailchimp Transactional Email (formerly Mandrill) sends targeted and event-driven messages via the API or SMTP, fast—with best-in-class deliverability.
Install mailchimp in your project
npm install mailchimp-api
From client controller call the server-controller with required data
 Don't forget to add $http to the top of controller
$http({
    method : 'POST',
    url : '/mailchimp-users/subscribe',
    data : {user:this.name}}).
        success(function(response) {
    console.log("hai this is basic test" + response);
    $scope.send = response.message;
}).error(function(response) {
    $scope.error = response.message;
});
In server controller Add this to the beginning of page
var MailchimpUser = mongoose.model('MailchimpUser'),
_ = require('lodash'),
mcapi = require('mailchimp-api');
var apiKey = '4bf6fb8820c333da4179216c3c2ef8fb-us10';
// Change this to your Key
var listID = 'ebbf193760';
var mc = new mcapi.Mailchimp(apiKey, {version: '2.0'});
Add this function
exports.subscribe = function(req, res) {
    var entry = req.body.user;
    var mcReq = {
        apikey: '4bf6fb8820c333da4179216c3c2ef8fb-us10',
        id: 'ebbf193760',
        email: {email: entry + '@gmail.com'},
        merge_vars: {
            FNAME: 'subscriber-first-name',
            LNAME: 'subscriber-last-name'
        },
        'double_optin': false,
        'send_welcome': true
    }
    // submit subscription request to mail chimp
    mc.lists.subscribe(mcReq, function(data) {
        console.log(data);
    }, function(error) {
        console.log(error);
    });
};
Add this route your route file
app.route('/mailchimp-users/subscribe')
   .post(mailchimpUsers.subscribe);
I've been unable to use the Mailchimp API directly but the REST API is pretty easy to use.
In main.js, create a Cloud Function. Enter your API key and update the REST URL to point at the correct Mailchimp data center (http://apidocs.mailchimp.com/api/2.0/)
var mailchimpApiKey = "<<REPLACE_WITH_YOUR_KEY>>";
Parse.Cloud.define("SubscribeUserToMailingList", function(request, response) {
  if (!request.params ||
        !request.params.email){
    response.error("Must supply email address, firstname and lastname to Mailchimp signup");
    return;
  }
  var mailchimpData = {
    apikey  : mailchimpApiKey,
    id      : request.params.listid,
    email   : {
      email : request.params.email
    },
    merge_vars : request.params.mergevars
  }
  var url = "https://<<REPLACE_WITH_DATA_CENTRE>>.api.mailchimp.com/2.0/lists/subscribe.json";
  Parse.Cloud.httpRequest({
    method: 'POST',
    url: url,
    body: JSON.stringify(mailchimpData),
    success: function(httpResponse) {
      console.log(httpResponse.text);
      response.success("Successfully subscribed");
    },
    error: function(httpResponse) {
      console.error('Request failed with response code ' + httpResponse.status);
      console.error(httpResponse.text);
      response.error('Mailchimp subscribe failed with response code ' + httpResponse.status);
    }
  });
});
Then, in the code which calls this function... (replace your list ID)
Parse.Cloud.run("SubscribeUserToMailingList", {
    listid      : "<<REPLACE_WITH_LIST_ID>>",
    email       : email,
    mergevars   : {
        FNAME   : firstName,
        LNAME   : lastName
    }
})
.then(function(success){
    console.log("Successfully subscribed");
    // ...
},
function(error){
    console.log("Unable to subscribe");
    // ...
});
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With