A Meteor wrapper for the MailChimp API.
- node-mailchimp - A node.js wrapper for the MailChimp API
meteor-mailchimp exposes the following features of the MailChimp API to your Meteor application:
- MailChimp API v2.0
Further information on the MailChimp API and its features is available at https://github.com/gomfunkel/node-mailchimp.
meteor-mailchimp also exposes one template you can use out of the box: MailChimpListSubscribe
, which you can use to enable your visitors to subscribe to your mailing list(s).
Install using Meteorite - Installer & smart package manager for Meteor:
$ mrt add mailchimp
Use in your template:
<div id="subscribeForm">
{{> MailChimpListSubscribe}}
</div>
Put in your server's Meteor.startup():
MailChimpOptions.apiKey = "<Your MailChimp API Key>";
MailChimpOptions.listId = "<ID of your default mailing list>";
This way you don't have to pass these parameters on each call.
MailChimp 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 option:
version
The API version to use. Defaults to 2.0.
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 both on the server and the client. 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:
if ( Meteor.isServer ) {
// Set it once and reuse many times
MailChimpOptions.apiKey = "<Your MailChimp API Key>";
MailChimpOptions.listId = "<ID of your default mailing list>";
}
try {
// You can as well pass different parameters on each call
var api = new MailChimp( /* apiKey, { version : '2.0' } */ );
} catch ( error ) {
console.log( error.message );
}
api.call( 'campaigns', 'list', { start: 0, limit: 25 }, function ( error, result ) {
if ( error )
console.log( error.message );
else
console.log( JSON.stringify( result ) ); // Do something with your data!
});
api.call( 'campaigns', 'template-content', { cid: '/* CAMPAIGN ID */' }, function ( error, result ) {
if ( error )
console.log( error.message );
else
console.log( JSON.stringify( result ) ); // Do something with your data!
});
- Initial release
Copyright © 2014 Miroslav Hibler
meteor-mailchimp is licensed under the MIT license.