Created
November 17, 2016 01:41
-
-
Save iamkevingreen/4ab397ae41ddde34835b71a2237cebec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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