Coder Social home page Coder Social logo

node-mailchimp's Introduction

node-mailchimp

A node.js wrapper for the MailChimp API.

node-mailchimp exposes the following features of the MailChimp API to your node.js application:

  • MailChimp API (Versions 2.0, 1.3, 1.2 and 1.1)
  • MailChimp Export API (Version 1.0)
  • MailChimp Webhooks
  • MailChimp OAuth2 authorization
  • MailChimp Partner API (Version 1.3)
  • Mandrill API (Version 1.0)

Further information on the MailChimp API and its features is available at http://apidocs.mailchimp.com. If you want to know more about the Mandrill API and its features have a look at https://mandrillapp.com/api/docs/.

Table of Contents

Installation

Installing using npm (node package manager):

npm install mailchimp

If you don't have npm installed or don't want to use it:

cd ~/.node_libraries
git clone git://github.com/gomfunkel/node-mailchimp.git mailchimp

Please note that parts of node-mailchimp depend on request by Mikeal Rogers. This library needs to be installed for the API and Export API to work. Additionally node-querystring is needed for the Webhooks to work. If you are using npm all dependencies should be automagically resolved for you.

Usage

Information on how to use the MailChimp APIs can be found below. Further information on the API methods available can be found at http://apidocs.mailchimp.com. You can also find further information on how to obtain an API key, how to set up Webhooks and/or OAuth2 in your MailChimp account and much more on the MailChimp API pages.

Some methods of the MailChimp API take associative arrays as a parameter, for example the parameter merge_vars of the listSubscribe method. As there are no associative arrays in JavaScript you simply use an object with its properties being the keys, like in the following example:

var merge_vars = {
	EMAIL: '/* E-MAIL ADDRESS */',
	FNAME: '/* FIRST NAME */',
	LNAME: '/* LAST NAME */'
};

MailChimp API (when using MailChimp API version 2.0)

Attention: Support for v2.0 of the MailChimp API is not yet well tested. Please use with caution. When in doubt, stick to older versions of the API (v1.x) and skip to the next chapter for documentation.

MailChimpAPI takes two arguments. The first argument is your API key, which you can find in your MailChimp Account. The second argument is an options object which can contain the following options:

  • version The API version to use (1.1, 1.2, 1.3 or 2.0). Defaults to 1.3. Make sure to explicitly use 2.0 here or refer to the next chapter for documentation on older API versions.
  • userAgent Custom User-Agent description to use in the request header.

All of the API categories and methods described in the MailChimp API v2.0 Documentation (http://apidocs.mailchimp.com/api/2.0 are available in this wrapper. To use them the method call is used which takes four parameters:

  • section The section of the API method to call (e.g. 'campaigns').
  • method The method to call in the given section.
  • params Parameters to pass to the API method.
  • callback Callback function for returned data or errors with two parameters. The first one being an error object which is null when no error occured, the second one an object with all information retrieved as long as no error occured.

Example:

var MailChimpAPI = require('mailchimp').MailChimpAPI;

var apiKey = 'Your MailChimpAPI API Key';

try {
    var api = new MailChimpAPI(apiKey, { version : '2.0' });
} catch (error) {
    console.log(error.message);
}

api.call('campaigns', 'list', { start: 0, limit: 25 }, function (error, data) {
    if (error)
        console.log(error.message);
    else
        console.log(JSON.stringify(data)); // Do something with your data!
});

api.call('campaigns', 'template-content', { cid: '/* CAMPAIGN ID */' }, function (error, data) {
    if (error)
        console.log(error.message);
    else
        console.log(JSON.stringify(data)); // Do something with your data!
});

MailChimp API (when using MailChimp API version 1.x)

MailChimpAPI takes two arguments. The first argument is your API key, which you can find in your MailChimp Account. The second argument is an options object which can contain the following options:

  • version The API version to use (1.1, 1.2, 1.3 or 2.0). Defaults to 1.3.
  • secure Whether or not to use secure connections over HTTPS (true/false). Defaults to false.
  • userAgent Custom User-Agent description to use in the request header.

The callback function for each API method gets two arguments. The first one is an error object which is null when no error occured, the second one an object with all information retrieved as long as no error occured.

Example:

var MailChimpAPI = require('mailchimp').MailChimpAPI;

var apiKey = 'Your MailChimp API Key';

try {
    var api = new MailChimpAPI(apiKey, { version : '1.3', secure : false });
} catch (error) {
    console.log(error.message);
}

api.campaigns({ start: 0, limit: 25 }, function (error, data) {
    if (error)
        console.log(error.message);
    else
        console.log(JSON.stringify(data)); // Do something with your data!
});

api.campaignStats({ cid : '/* CAMPAIGN ID */' }, function (error, data) {
    if (error)
        console.log(error.message);
    else
        console.log(JSON.stringify(data)); // Do something with your data!
});

MailChimp Export API

MailChimpExportAPI takes two arguments. The first argument is your API key, which you can find in your MailChimp Account. The second argument is an options object which can contain the following options:

  • version The Export API version to use, currently only 1.0 is available and supported. Defaults to 1.0.
  • secure Whether or not to use secure connections over HTTPS (true/false). Defaults to false.
  • userAgent Custom User-Agent description to use in the request header.

The callback function for each API method gets two arguments. The first one is an error object which is null when no error occured, the second one an object with all information retrieved as long as no error occured.

Example:

var MailChimpExportAPI = require('mailchimp').MailChimpExportAPI;

var apiKey = 'Your MailChimp API Key';

try {
    var exportApi = new MailChimpExportAPI(apiKey, { version : '1.0', secure: false });
} catch (error) {
    console.log(error.message);
}

exportApi.list({ id : '/* LIST ID */'  }, function (error, data) {
    if (error)
        console.log(error.message);
    else
        console.log(JSON.stringify(data)); // Do something with your data!
});

MailChimp Webhooks

MailChimpWebhook takes one argument, an options object which can contain the following options:

  • port The port the server is going to listen on. Defaults to 8100.
  • secret Secret key as suggested on the Webhook page which is then simply added as a pathname to the Webhook URL in your MailChimp account and checked for. Nothing too fancy but a small enhancement to security. Leave empty (default setting) if you don't want to use a secret key. Example: If you set the secret to 'ChimpSecret' you need to enter the Webhook URL http://www.yourdomain.com/ChimpSecret in the MailChimp Webhook settings.
  • secure Credentials as generated by the crypto module. If present HTTPS support is enabled for the server. Defaults to false.

You can register the following events. The callback function for each of these events receive two arguments. The first argument is an object with the information retrieved, the second argument contains metadata like when the event occurred.

  • subscribe Emitted when someone subscribes to your list.
  • unsubscribe Emitted when someone unsubscribes from your list.
  • profile Emitted when someone updates his profile.
  • upemail Emitted when someone changes his email address. Please note that you will receive a profile event at the same time.
  • cleaned Emitted when an email address is cleaned from you list.
  • campaign Emitted when a campaign is sent for your list.

Example:

var MailChimpWebhook = require('mailchimp').MailChimpWebhook;

var webhook = new MailChimpWebhook();

webhook.on('error', function (error) {
    console.log(error.message);
});

webhook.on('subscribe', function (data, meta) {
    console.log(data.email+' subscribed to your newsletter!'); // Do something with your data!
});

webhook.on('unsubscribe', function (data, meta) {
    console.log(data.email+' unsubscribed from your newsletter!'); // Do something with your data!
});

MailChimp OAuth2

MailChimpOAuth takes one argument, an options object which can contain the following options:

  • clientId The clientId can be obtained from MailChimp, please refer to the API docs on how to do this. The clientId is a required parameter.
  • clientSecret The clientSecret can be obtained from MailChimp, please refer to the API docs on how to do this. The clientSecret is a required parameter.
  • redirectUri Redirect URI from MailChimp App Configuration
  • ownServer Boolean to enable own custom server for listening to redirect URI. Defaults to false.
  • addPort Boolean to add value of port number in redirectUri defaults to false.
  • port The port the server is going to listen on. Defaults to 8100. These fields are not needed if ownServer is false
  • finalUri After a successful authorization on the MailChimp website the user is redirected to this URI, if any.
  • secure Credentials in the form {key:path to ssl key file, cert: path to ssl certificate file} . If present HTTPS support is enabled for the server. Defaults to false.

You can register the following events:

  • error This event is emitted when an error occured and receives one argument that contains the error message.
  • authed Emitted when the OAuth was completed successfully. Receives one argument which represents the API key in custom object with metadata that can be passed on to other API functionality.

Example:

var MailChimpOAuth = require('mailchimp').MailChimpOAuth;
var MailChimpAPI = require('mailchimp').MailChimpAPI;

var options = {
	clientId: 'Your MailChimp client id',
	clientSecret: 'Your MailChimp client secret',
	redirectUri: 'http://www.example.com',
	ownServer: true,
	addPort: true,
	finalUri: 'http://www.example.com/successfulLogin.html'
};

var oauth = new MailChimpOAuth(options);

console.log(oauth.getAuthorizeUri()); // The MailChimp login URI the user needs to be sent to
<!-- Error contains custom Data when passed around to know the current status-->
oauth.on('error', function (error) {
    console.log(error.err);
});

oauth.on('authed', function (data) {

	try {
	    var api = new MailChimpAPI(data.apiKey, { version : '1.3', secure : false });
	} catch (error) {
	    console.log(error.message);
	}

    api.campaigns({ start: 0, limit: 25 }, function (error, data) {
        if (error)
            console.log(error.message);
        else
            console.log(JSON.stringify(data)); // Do something with your data!
    });

});

MailChimp Partner API

MailChimpPartnerAPI takes two arguments. The first argument is your app key, which you can generate and find in your MailChimp Account, if you are eligible to use the Partner API. The second argument is an options object which can contain the following options:

  • version The Partner API version to use, currently only 1.3 is available and supported. Defaults to 1.3.
  • secure Whether or not to use secure connections over HTTPS (true/false). Defaults to false.
  • userAgent Custom User-Agent description to use in the request header.

The callback function for each API method gets two arguments. The first one is an error object which is null when no error occured, the second one an object with all information retrieved as long as no error occured.

Example:

var MailChimpPartnerAPI = require('mailchimp').MailChimpPartnerAPI;

var appKey = 'Your MailChimp app key';

try {
    var api = new MailChimpPartnerAPI(appKey, { version : '1.3', secure : false });
} catch (error) {
    console.log(error.message);
}

api.checkUsername({ username: '/* USERNAME */' }, function (error, data) {
    if (error)
        console.log(error.message);
    else
        console.log(JSON.stringify(data)); // Do something with your data!
});

Mandrill API

MandrillAPI takes two arguments. The first argument is your API key, which you can find in your Mandrill Account. The second argument is an options object which can contain the following options:

  • version The Mandrill API version to use, currently only 1.0 is available and supported. Defaults to 1.0.
  • secure Whether or not to use secure connections over HTTPS (true/false). Defaults to false.
  • userAgent Custom User-Agent description to use in the request header.

All of the API categories and methods described in the Mandrill API Documentation (https://mandrillapp.com/api/docs/) are available in this wrapper. To use the the method call is used which takes four parameters:

  • category The category of the API method to call (e.g. 'users').
  • method The method to call in the given category.
  • params Parameters to pass to the API method.
  • callback Callback function for returned data or errors with two parameters. The first one being an error object which is null when no error occured, the second one an object with all information retrieved as long as no error occured.
var MandrillAPI = require('mailchimp').MandrillAPI;

var apiKey = 'Your Mandrill API Key';

try {
    var mandrill = new MandrillAPI(apiKey, { version : '1.0', secure: false });
} catch (error) {
    console.log(error.message);
}

mandrill.call('tags', 'time-series', { tag : '/* TAGNAME */'  }, function (error, data) {
    if (error)
        console.log(error.message);
    else
        console.log(JSON.stringify(data)); // Do something with your data!
});

MailChimp STS API

MailChimpSTSAPI is no longer part of this wrapper as of version 1.0.1 because the API was discontinued by MailChimp.

License

node-mailchimp is licensed under the MIT License. (See LICENSE)

node-mailchimp's People

Contributors

abtris avatar bradaric avatar cbrady321 avatar cyberwombat avatar davidwood avatar dennismartensson avatar gomfunkel avatar ibash avatar ivesdebruycker avatar ms76 avatar novemberborn avatar olawiberg avatar psilva261 avatar sumit0k avatar thequazz avatar timisbusy avatar tingham avatar winfred avatar wulfsolter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-mailchimp's Issues

API v3.0 support

Any plans for adding this? I see that v2.0 will be unsupported after 2016, so adding support for it is probably a good idea at this point, unless of course it already supports it.

searchMembers query using merge tag not working

I'm trying to search members by a specific merge tag, but when I do, I returns no results. Code snippet below:

api.searchMembers({ query: 'PRET_ID:199' }, function (error, data) {
        if (error) {
            console.log(error.message);
            return;
        }
        console.log(JSON.stringify(data));
    });

missing error handling

Ran into issues with the CampaignSubscriberActivity function, JSON.parse needs to be wrapped in try/catch.

serialize not defined

When using the STS api I get an error that serialize is not defined:

/home/node/node-service/releases/2012-05-25T18-29-32.182419619/node_modules/mailchimp/lib/mailchimp/helpers.js:24
                output.push(serialize(value[name], key != '' ? key + '[' + nam
                            ^
ReferenceError: serialize is not defined

Looks like this commit resolved this issue, but is not present in v0.8.0

encodeURIComponent breaks Mandrill compatibility

I'm not sure if this is an issue in my implementation, Mandrill, or what, but 2e3c1e9 introduced the encodeURIComponent call to the body string which cases Mandrill to throw errors. Specifically:

[Error: You must specify a key value]

After removing encodeURIComponent from the MandrillAPI_v1_0.js file, the calls succeed.

The API method lists_batch_subscribe does not exist

Hello!

I'm making a call to API 2.0 using the following code:

var mailChimpApi = new MailChimpAPI(
  parameters.mailing.mailchimpKey, {
    version : '2.0'
  }
);
mailChimpApi.call('lists', 'batch-subscribe', {
  id: list.listId,
  batch: subscribeBatch,
  double_optin: false,
  update_existing: true
}, function () { /** ... */ });

Method description: https://apidocs.mailchimp.com/api/2.0/lists/batch-subscribe.php

I'm getting the following error: The API method lists_batch_subscribe does not exist.

Please advise! Thank you!

EADDRINUSE error with OAuth

So if I make more than one request to the OAuth code it dies with an EADDRINUSE error due to the server being already spawned. Is there a workaround?

Thanks

Subscriber is not added to the List. why?

I have tried and here is my code:


var cfg = require('./config'),
errorCode = require('./errorCode');

var MailChimpAPI = require('mailchimp').MailChimpAPI;

var apiKey = cfg.mailchimp_apiKey;

try {
var api = new MailChimpAPI(apiKey, { version : '1.3', secure : false });
} catch (error) {
console.log('Unable to create MailChimp: ' + error.message);
}

module.exports.listSubscribe = function(param, next){
console.log("Add " + param.email + " to " + cfg.mailchimp_subListId);
api.listSubscribe ({id:cfg.mailchimp_subListId, email_address:param.email}, function(err, data) {
if (err) {
next(errorCode.gen( '00000', JSON.stringify(err)));
} else {
next(null, data);
}
});

}

When I call this, it returns true. but, when I check my account, there is no email added to the subscribe list. Why?

listSubscribe problem: merge_vars not making it to MailChimp.

Not sure if anybody else has noticed but adding a merge_var (I happen to be using a custom one for a registration link) to the mer_vars array in the listSubscribe method does not seem to be working.

I've made this a required field and the API comes back with

{"error":"REGLINK must be provided - Please enter a value","code":250}

I've debugged this quite extensively and my guess right now is that there is a problem in the request initialization block in main.js.

breaking out of async.waterfall

I am looping over an array (using forEachSeries) and each iteration calls an async.waterfall function which includes a call to listMemberInfo.

The problem is that it seems to be returning results out of order, breaking out of the waterfall, and even the forEachSeries.

merge_vars is supposed to be an array not a hash

As per the Mailchimp API spec, merge_vars when used in the listSubscribe call, for example, is defined as an array, not a hash.

This is how it is implemented in the PHP Mailchimp API wrapper, and is confusing that the module silently fails (subscribes the user, no merge tags are sent to Mailchimp, even though I have followed the spec to the letter). This took quite a while to debug.

Test 1:

merge_vars =
[ { GENDER: 'male' },
{ FNAME: 'Arush' },
{ LNAME: 'Sehgal' } ]

Expected behaviour, error thrown - this is an array of hashes, needs to be an array
Actual behaviour, silently fails, no error, but Mailchimp merge tags are not updated

Test 2:

merge_vars =
{ GENDER: 'male',
FNAME: 'Arush',
LNAME: 'Sehgal' }

Expected behaviour, error thrown - this is a hash, not an array. Needs to be an array
Actual behaviour, works.

Test 3:

merge_vars =
[ 'GENDER' : 'male',
'FNAME' : 'Arush',
'LNAME' : 'Sehgal' ]

Expected behaviour, works.
Actual behaviour, silently fails, no error, but Mailchimp merge tags are not updated

However, given that this fix is likely to break a lot of peoples' code, you should probably make all three tests work, and just show warnings for Tests 1 and 2 since they are not as per the spec.

Export API

Using the campaignSubscriberActivity api, I get an "unexpected end of input" error if there is no activity to return. Not sure how best to address this.

Webhook not working

The webhook code depends on querystring to parse arrays PHP-style (eg data[email]). I believe this functionality has been removed from querystring, so all fields are returned as literal strings, so payload.type works but payload.data is undef because its actually storing payload."data[email]" (forgive the syntax).

If you try the code you give in the readme for an example webhook it fails on this because data is undef. A console.log on payload gives:

{ type: 'subscribe',
fired_at: '2009-03-26 21:35:57',
'data[id]': '8a25ff1d98',
'data[list_id]': 'a6b5da1054',
'data[email]': '[email protected]',
'data[email_type]': 'html',
'data[merges][EMAIL]': '[email protected]',
'data[merges][FNAME]': 'MailChimp',
'data[merges][LNAME]': 'API',
'data[merges][INTERESTS]': 'Group1,Group2',
'data[ip_opt]': '10.20.10.30',
'data[ip_signup]': '10.20.10.30' }

-Mark

Template Language issue

I successfully connected to my MailChimp account and managed to create a new campaign. The scenario would be that every time I create a new 'newsboard' in my application I create a MailChimp Campaign using a template and the content of the newsboard. I am trying to use MailChimp Template Language for this: http://templates.mailchimp.com/getting-started/template-language/

var optionsObj = {
                 list_id: 'xxx',
                 subject: 'xxx',
                 from_email: 'xxx',
                 from_name: 'xxx',
                 template_id: 'xxx',
                 to_name: 'xxx',
             };

             var contentObj = {
                 sections: {
                     "header": 'Test Header title!',
                     "header2": 'Test Header title 2!',
                     "date": 'Test Date'
                 }
             };

             //Mailchimp call
             api.call('campaigns', 'create', { type: 'regular', options: optionsObj, content: contentObj }, function(error, data) {
                 if (error)
                     console.log(error.message);
                 else
                     console.log(JSON.stringify(data)); // Do something with your data!
                     //send it
             });

In the MailChimp Template editor I have the following HTML code:

<div mc:edit="header"> /* content */ </div>
<div mc:edit="header2"> /* content */ </div>
<div mc:edit="date"> /* content */ </div>

Is there another way to do this or get around, or am I doing something wrong?

API has no method 'campaigns'

I've been trying to use node-mailchimp (with the 1.3 API) inside a Meteor app and I'm running into a strange issue.

I'm initializing the API as described in the readme:

    try { 
      var mailChimp = new MailChimpAPI(MAILCHIMP_API_KEY, { version : '1.3', secure : false });
    } catch (error) {
      console.log(error.message);
    }

And I've successfully used it to subscribe new users to a list. This works fine:

    mailChimp.listSubscribe({
      id: MAILCHIMP_LIST_ID,
      email_address: '[email protected]',
      double_optin: false
    }, function(error, result){
      if(error)
        console.log(error)
      else
        console.log(result)
    });

On the other hand, campaign functions don't work. For example this:

    mailChimp.campaigns({ start: 0, limit: 5 }, function (error, data) {
      if (error)
          console.log(error.message);
      else
          console.log(JSON.stringify(data)); // Do something with your data!
    });

Returns this error:

Exception while invoking method 'campaign' TypeError: Object [object Object] has no method 'campaigns'
    at Meteor.methods.campaign (app/server/campaigns.js:59:11)

Any idea what I'm doing wrong, or how I could debug the problem? Thanks in advance :)

Need docs on how to run tests

I tried

$ ./node_modules/.bin/vows --verbose --spec test/**/*

but I always get

✗ Errored » 1 errored

I'm not sure which test is failing, or how to run the other tests.

redirectUri and serverUri swapped in oauth

It appears that the redirectUri passed into the oauth option hash isn't used in generating the authorize uri. After chasing my tail for a little while and wondering why I kept getting a redirect_uri_mismatch, I took a look at the getAuthorizeUri function on line 175, and it looks like the issue is on line 180. Here's the full text:

MailChimpOAuth.prototype.getAuthorizeUri = function () {

    var params = {
        response_type: 'code',
        client_id: this.clientId,
        redirect_uri: this.serverUri+':'+this.httpPort
    };

    return 'https://login.mailchimp.com/oauth2/authorize?'+querystring.stringify(params);

}

I'm guessing the third param should be redirect_uri: this.redirectUri

datacenter not deriving from auth token

In MailChimpAPI_v2_0.js the constructor takes an apiKey which is split and then uses as the datacenter prefix for .api.mailchimp.com. If I have already negotiated an oauth token externally to your library, currently need to fudge the API key so the datacenter is correctly derived from the user profile, and then force the actual auth token attribute

My current workflow is something like this :

getAPI = function(sysImports) {  
  var api = new MailChimpAPI(
      ' -' + JSON.parse(sysImports.auth.oauth.profile).dc,       
      {    
        version : '2.0'
    }
  );
  api.apiKey = sysImports.auth.oauth.token;
  return api;
}

... to get the right dc.

Is there a better way to use prenegotiated oauth profile and token or can I please otherwise request that datacenter be part of MailChimpAPI_v2_0 constructor options

Unit Tests?

Are there any unit tests for this client api wrapper? If not, do you intend on adding them anytime soon?

Thanks!

Better output when no connection

I'm struggling to debug why locally my application can connect to the MailChimp API but my (also local) Dokku instance cannot. I've checked that my Dokku instance has network access.

It'd be handy to see what kind of response is given back from the API request, rather than the arbitrary "Could not connect to endpoint".

0.9.0 Draft campaigns

There is some issue with handling draft campaigns

async.parallel 
  stats: (cb) ->
    mailchimp.campaignEmailStatsAIMAll {cid: campaignId}, cb
  bounces:  (cb) ->
    mailchimp.campaignBounceMessages {cid: campaignId}, cb
, (err, rawStats) ->
  ...

this code worked with previous versions, now works only when i delete draft campaigns

Library not handling Gzip compression, breaking response

http://stackoverflow.com/questions/33992930/error-error-parsing-json-answer-from-mailchimp-api

Getting an error from the NodeJS MailChimp - using:

https://github.com/gomfunkel/node-mailchimp

Error: Error parsing JSON answer from MailChimp API: �V_.I,)-V�RJ-_�/R�QJ�OIU�220�Q�K�2�|2�K�]�S���K+��*�j+%ϼ�Ĝ���������jO+SKK�Z��T��c
I do not understand why this is happening, my calls are pretty vanilla, see below:

var MailChimpAPI = require('mailchimp').MailChimpAPI,
apiKey = 'asaas',
mainListId = 45949;

try {
var api = new MailChimpAPI(apiKey, {version: '2.0'});
} catch (error) {
console.log(error.message);
}

var options = {
id: mainListId, //12345
email: {
email: email //[email protected]
},
double_optin: false,
send_welcome: false
};

console.log(options);

api.call('lists', 'subscribe', options, function (error, data) {
if (error) {
console.log(error.message);
callback(error, null);
} else {
console.log(JSON.stringify(data)); // Do something with your data!
callback(null, data);
}
});

Dont use `||` operator for boolean values

You should try another way of extrapolating default values for boolean fields. For example here:

https://github.com/gomfunkel/node-mailchimp/blob/master/lib/mailchimp/MailChimpAPI_v1_3.js#L1172

When I use this code:

  mailchimpApi.listSubscribe({ 
    id: 'some_list',
    email_address: '[email protected]',
    merge_vars: {
      double_optin: false
    }
  }, function () { /* do something */ });

The value actually passed to mailchimp will be null because the || operator evaluates the first "truthy" value of which false is not. Updating the field to use the string "false" is an appropriate work-around because false would have been stringified anyway, but its a disconnect for many Javascript programmers.

MailChimp API 3.0

Hello,
Do you planning to implement API for version 3.0?
Thanks, Anton

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.