Skip to content

Instantly share code, notes, and snippets.

@iamkevingreen
Created November 17, 2016 01:41
Show Gist options
  • Save iamkevingreen/4ab397ae41ddde34835b71a2237cebec to your computer and use it in GitHub Desktop.
Save iamkevingreen/4ab397ae41ddde34835b71a2237cebec to your computer and use it in GitHub Desktop.
'use strict'
const Mailchimp = require("mailchimp-api-v3");
const mailchimp = new Mailchimp(process.env.MAILCHIMP_API);
exports.register = (server, options, next) => {
const postMailChimp = (request, reply) => {
let object = JSON.parse(request.payload)
mailchimp.post('/lists/########/members', {
email_address: object.email,
status: 'subscribed'
})
.then((res) => reply(null, JSON.stringify(res)))
.catch((err) => reply(null, JSON.stringify(err)));
}
server.route({
method: "POST",
path: '/subscribe',
handler: (request, reply) => postMailChimp(request, reply)
})
next();
}
exports.register.attributes = {
name: 'newsletter',
version: '1.0.0'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment