Coder Social home page Coder Social logo

meteor-mailchimp's Introduction

miro:mailchimp

A Meteor wrapper for the MailChimp API.

See also these wrappers:

Dependencies

TL;DR;

miro:mailchimp provides MailChimp API v2.0 (v3.0 not ready yet!) features to your Meteor application.

Installation

Install using Meteor:

meteor add miro:mailchimp

Quick Start

NOTE: starting with v1.1.0 the template MailChimpListSubscribe is NOT included in the package anymore BUT the template helpers and event handlers ARE! In other words, you can copy the old template from the example folder within the package or copy it from here,...

<!-- Bootstrap example -->
<template name="MailChimpListSubscribe">
	<form class="form-inline">
	{{#if message}}
		<p class="mailchimp-message">{{{message}}}</p>
	{{/if}}
		<div class="form-group">
			<input class="mailchimp-email form-control" type="email" placeholder="[email protected]"/>
			<input type="submit" value="Subscribe" class="mailchimp-subscribe btn btn-success" />
		</div>
	</form>
</template>

...include it in your code and customize it as you wish; it will be inherently functional as long as its name remains MailChimpListSubscribe and it contains all template expressions and CSS classes (apart from bootstrap ones, of course) as the original example has.

Include it in some other template as needed:

<div id="subscribeForm">
	{{> MailChimpListSubscribe}}
</div>

Finally, put in your server's settings.json:

{
	"private": {
		"MailChimp": {
			"apiKey": "<Your MailChimp API Key>",
			"listId": "<ID of your default mailing list>"
		}
	}
}

and start your server with:

meteor --settings=settings.json

API

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 are available in this wrapper both server- and client-side.

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 (optional server-side, required client-side) 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.

NOTE: If callback is ommited server-side, the method runs "synchronously" via Meteor.wrapAsync method.

Examples

Callback, server-side/client-side

// You can as well pass different parameters on each call
var mailChimp = new MailChimp( /* apiKey, { version: '2.0' } */ );

mailChimp.call( 'campaigns', 'list', {
		start: 0,
		limit: 25
	},
	// Callback beauty in action
	function ( error, result ) {
		if ( error ) {
			console.error( '[MailChimp][Campaigns][List] Error: %o', error );
		} else {
			// Do something with your data!
			console.info( '[MailChimp][Campaigns][List]: %o', result );
		}
	}
);

wrapAsync, server-side ONLY

// You can as well pass different parameters on each call
var mailChimp = new MailChimp( /* apiKey, { version: '2.0' } */ );

var result = mailChimp.call( 'campaigns', 'list', {
	start: 0,
	limit: 25
});

// Do something with your data!
console.info( '[MailChimp][Campaigns][List]: %o', result );

Changelog

v1.1.0

  • Removed subscribe template (moved to example folder) so it can be customized
  • Some bug fixes

v1.0.4

  • Reinstated server-side callback in case someone still wants to use it instead of Meteor.wrapAsync method (#19)
  • Updated documentation (README.md)

v1.0.3

  • Fixed bug with Meteor.wrapAsync not returning real error (#16)
  • Fixed bug with audit-argument-checks package throwing 'Did not check()' error (#15)

v1.0.2

  • Bumped version number

v1.0.1

  • README.md fix

v1.0.0

  • Update to Meteor v1.0
  • Bug fixes
  • Cleanup

v0.4.2

  • Fixed typo in README.md

v0.4.1

  • Updated README.md to reflect changes in v0.4.0

v0.4.0

  • Introduce settings.json for MailChimpOptions
  • If already subscribed show different message then success message

v0.3.0

  • Enable submit with return key

v0.2.0

  • On client, MailChimp.call() now reads API Key from session variable 'MailChimpOptions.apiKey' as well

v0.1.0

  • Initial release

Copyright and license

Copyright © 2014-1015 Miroslav Hibler

miro:mailchimp is licensed under the MIT license.

meteor-mailchimp's People

Contributors

mirohibler avatar sachag 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

meteor-mailchimp's Issues

API not returning error code - Meteor internal server error

when I enter an email that is already subscribed the message is Internal Server Error

Console logs the exception as follows:

I20141209-22:08:19.329(-8)? Exception while invoking method 'MailChimp' Error: [email protected] is already subscribed to the list.
I20141209-22:08:19.329(-8)?     at Object.Future.wait (/Users/rob/.meteor/packages/meteor-tool/.1.0.36.1fqdx34++os.osx.x86_64+web.browser+web.cordova/meteor-tool-os.osx.x86_64/dev_bundle/lib/node_modules/fibers/future.js:326:15)
I20141209-22:08:19.329(-8)?     at packages/meteor/helpers.js:118
I20141209-22:08:19.329(-8)?     at MailChimp.call (packages/miro:mailchimp/lib/server/mailchimp.js:43)
I20141209-22:08:19.329(-8)?     at Meteor.methods.MailChimp (packages/miro:mailchimp/lib/server/mailchimp.js:67)
I20141209-22:08:19.329(-8)?     at maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1599)
I20141209-22:08:19.330(-8)?     at packages/ddp/livedata_server.js:648
I20141209-22:08:19.330(-8)?     at _.extend.withValue (packages/meteor/dynamics_nodejs.js:56)
I20141209-22:08:19.330(-8)?     at packages/ddp/livedata_server.js:647
I20141209-22:08:19.330(-8)?     at _.extend.withValue (packages/meteor/dynamics_nodejs.js:56)
I20141209-22:08:19.330(-8)?     at _.extend.protocol_handlers.method (packages/ddp/livedata_server.js:646)
I20141209-22:08:19.330(-8)?     - - - - -
I20141209-22:08:19.330(-8)?     at Object.module.exports.createMailChimpError (/Users/rob/.meteor/packages/miro:mailchimp/.1.0.2.vblm2o++os+web.browser+web.cordova/npm/node_modules/mailchimp/lib/mailchimp/helpers.js:49:14)
I20141209-22:08:19.330(-8)?     at Request._callback (/Users/rob/.meteor/packages/miro:mailchimp/.1.0.2.vblm2o++os+web.browser+web.cordova/npm/node_modules/mailchimp/lib/mailchimp/MailChimpAPI_v2_0.js:72:22)
I20141209-22:08:19.330(-8)?     at Request.self.callback (/Users/rob/.meteor/packages/miro:mailchimp/.1.0.2.vblm2o++os+web.browser+web.cordova/npm/node_modules/mailchimp/node_modules/request/request.js:372:22)
I20141209-22:08:19.331(-8)?     at Request.emit (events.js:98:17)
I20141209-22:08:19.331(-8)?     at Request.<anonymous> (/Users/rob/.meteor/packages/miro:mailchimp/.1.0.2.vblm2o++os+web.browser+web.cordova/npm/node_modules/mailchimp/node_modules/request/request.js:1317:14)
I20141209-22:08:19.331(-8)?     at Request.emit (events.js:117:20)
I20141209-22:08:19.331(-8)?     at IncomingMessage.<anonymous> (/Users/rob/.meteor/packages/miro:mailchimp/.1.0.2.vblm2o++os+web.browser+web.cordova/npm/node_modules/mailchimp/node_modules/request/request.js:1265:12)
I20141209-22:08:19.331(-8)?     at IncomingMessage.emit (events.js:117:20)
I20141209-22:08:19.331(-8)?     at _stream_readable.js:929:16
I20141209-22:08:19.331(-8)?     at process._tickCallback (node.js:419:13)

Here's the relevant client console log bit:

Error
    details: undefined
    error: 500
    errorType: "Meteor.Error"
    message: "Internal server error [500]"
    reason: "Internal server error"
    stack: "errorClass@http://localhost:3000/packages/meteor.js?61916b1060b3aa31a2...

This is a hack I'm using for now in the client side subscribe.js-

        case 500: // 'List_AlreadySubscribed'
          showMessage( subscribeAlreadySubscribed );
          break;

totally wrong but I'm in a rush

TypeError: Object #<Object> has no method 'methods'

I'm not sure if this is an issue with this library or meteor, but when install this and run meteor, I get the following...

TypeError: Object #<Object> has no method 'methods'
  at Package (packages/miro:mailchimp/lib/server/mailchimp.js:57:1)
  at /path/to/project/.meteor/local/build/programs/server/packages/miro_mailchimp.js:105:4
  at /path/to/project/.meteor/local/build/programs/server/packages/miro_mailchimp.js:114:3
  at /path/to/project/.meteor/local/build/programs/server/boot.js:222:10

Example Code Returns No Campaigns

I am using your example code to make sure that MailChimp is setup correctly. I am getting back the following from Meteor:

I20150225-17:18:30.937(-7)? [MailChimp][Campaigns][List]:  { total: 0, data: [], errors: [] }

My API key works for adding subscribers, just not for using the .call method. Is there an issue with the code in the examples?

Updating settings.json from a form inside your app

Hey,

Is there a way to change the mailchimp api key and list id in settings.json through a form that exists on the app?

For example, if I have a subscribe form on my blog, and I can log in to the admin section and update the subscription form info through a cms. Any idea if that's possible somehow? Thanks.

Pressing Enter submits the form through the browser

I seem to have got it all working, however I need to actually push the button for it to run through the API, when a user presses Enter the form submits through the browser html form. Is this supposed to happen? Is it happening for everyone or just me?

MailChimp is not defined

In Meteor 0.8.0, did a fresh 'mrt add mailchimp' and none of the Mailchimp methods are available. Any special tricks to get things working in 0.8?

Page refreshes on enter button press

In your documentation you give the example:

<form class="form-inline">
    {{#if message}}
        <p class="mailchimp-message">{{{message}}}</p>
    {{/if}}
    <div class="form-group">
        <input class="mailchimp-email form-control" type="email" placeholder="[email protected]"/>
        <button class="mailchimp-subscribe btn btn-success" type="button">Subscribe</button>
    </div>
</form>

The Subscribe button should be:

<input type="submit" class="mailchimp-subscribe btn btn-success" value="Subscribe" />

This prevents the page from refreshing on user pressing the enter key to after typing in their email address.

I will be glad to submit a PR to fix your README (I'm trying to get more into open source contribution, so I'll happily do this!)

Options without settings.json

After updating to meteor-mailchimp 4.0, I can no longer set options in Meteor.startup() and I have to use settings.json. Am I missing something?

Changing message value.

How would I go about changing the value of the messages?

var subscribeMessage            = 'Get on the mailing list:',
    subscribeInvalidEmail       = 'Invalid email address :(',
    subscribeSubscribing        = 'Subscribing...',
    subscribeSuccess            = 'Oh joy! Check your inbox! :)',
    subscribeAlreadySubscribed  = 'Already subscribed! O.o';

Template enhancement

What would be great is maybe a template defining possibility , similar to the blog and accounts-entry package
Some kind of MailChimp.config where you could define your own template, defaulting back to original to {{> MailChimpListSubscribe}} if none is declared

make compatible with react

Thanks for the package. It depends on blaze. would be great to make it so you could drop-in with react

Add documentation/features for security

Not sure if I missed something obvious, but with this plus the mailchimp-lists package installed, as a non-logged-in user I can run:

l = new MailChimpLists()
l.refresh()
l.lists()

in my Firebug console and get all sorts of juicy data about my lists, even if I'm not logged in.

Did I miss something in the docs about how to secure these methods from client-side access? My API keys are private but this still somehow manages to leak access to non-privileged users.

Error: No API Key Defined

Where do I put the settings.json file? I have it in a server folder... I ran meteor --settings settings.json and still no success.

Passing merge fields

Is there a way to pass merge fields along with the email address? I would like to pass fields like name and language?

Publishing latest version

Just wondering if you've had a chance to publish the new changes to the package back to Atmosphere?

Changes messages

I think there should be a way to change the {{ message }}. It would be really nice for copywriting purposes.

Callback not triggering?

For some reason, my callbacks on api.call() are not triggering at all, even though the API call seems to be succeeding. Any idea why that might be happening?

Exception while invoking method 'MailChimp' Error

What am I doing wrong?
(Meteor 1.0.1)

I20141209-15:05:26.701(-8)? Exception while invoking method 'MailChimp' Error: Did not check() all arguments during call to 'MailChimp'
I20141209-15:05:26.762(-8)?     at _.extend.throwUnlessAllArgumentsHaveBeenChecked (packages/check/match.js:352)
I20141209-15:05:26.762(-8)?     at Object.Match._failIfArgumentsAreNotAllChecked (packages/check/match.js:108)
I20141209-15:05:26.762(-8)?     at maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1596)
I20141209-15:05:26.763(-8)?     at packages/ddp/livedata_server.js:648
I20141209-15:05:26.763(-8)?     at _.extend.withValue (packages/meteor/dynamics_nodejs.js:56)
I20141209-15:05:26.763(-8)?     at packages/ddp/livedata_server.js:647
I20141209-15:05:26.763(-8)?     at _.extend.withValue (packages/meteor/dynamics_nodejs.js:56)
I20141209-15:05:26.763(-8)?     at _.extend.protocol_handlers.method (packages/ddp/livedata_server.js:646)
I20141209-15:05:26.763(-8)?     at packages/ddp/livedata_server.js:546

Update: I'm getting subscription requests but the form message is Error: Internal server error with the above logging info

Any way to avoid including API key in code?

My app is both deployed and open-sourced, so even though my calls into the mailchimp API are on the server side, I'd need to avoid ever committing a version of code that contains my API keys.

Since the API key is included in settings.json (which can be excluded from version control) is there any way to utilize this copy of the key rather than require it in code? Thanks...

[MailChimp] Error: undefined - Unable to connect to the MailChimp API endpoint.

Worked on this for a few hours, but can't get past this error (above) on the api.call (obfuscated my settings of course)

Session.set( 'MailChimpOptions.apiKey', "XXXXXXXX");
Session.set( 'MailChimpOptions.listId', "YYYYYYYY");

try {
var api = new MailChimp( Session.get( 'MailChimpOptions.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!
});

// any ideas how to troubleshoot?

List ID required

Seems like I need to provide the list ID within the params of the call method, even though I set it along with the apiKey as follows:

MailChimpOptions.apiKey = "--key--";
MailChimpOptions.listId = "--id--";

var params = {
id: "<--id-->",
email: {
email: email
},
double_optin: false
}

(calling lists/subscribe)

If I don't include it, MC gives the following error:

"Error: -100 - You must specify a id value"

All code is running within a server method, invoked by the client at the point of submitting the form.

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.