Last active
October 4, 2018 08:34
-
-
Save bettysteger/3837cc3966ff7a89fb7a12b6ab73c8ea to your computer and use it in GitHub Desktop.
Add mailchimp subscriber on Firebase user signup (firebase function)
This file contains 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
const functions = require('firebase-functions'); | |
const Mailchimp = require('mailchimp-api-v3'); | |
// Listens for new firebase signups | |
exports.addMailchimpSubscriber = functions.auth.user().onCreate((user) => { | |
const mailchimp = new Mailchimp('{API-KEY}'); | |
mailchimp.post('/lists/{listID}/members', { | |
email_address: user.email, | |
status: 'subscribed' | |
}).then(function(results) { | |
console.log('added new firebase user', user.email, 'to mailchimp list'); | |
}) | |
.catch(function(err) { | |
console.log(err); | |
}) | |
return null | |
}); |
This file contains 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
{ | |
"name": "functions", | |
"description": "Cloud Functions for Firebase", | |
"scripts": { | |
"serve": "firebase serve --only functions", | |
"shell": "firebase functions:shell", | |
"start": "npm run shell", | |
"deploy": "firebase deploy --only functions", | |
"logs": "firebase functions:log" | |
}, | |
"dependencies": { | |
"firebase-admin": "~6.0.0", | |
"firebase-functions": "^2.0.3", | |
"mailchimp-api-v3": "^1.12.0" | |
}, | |
"private": true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In case the log of the Firebase Function says:
You need to switch to the Blaze plan (pay-as-go) to make outbound network requests to work. This plan can stay free, if you do not exceed the free usage limits.
https://stackoverflow.com/questions/47622607/is-it-safe-to-use-firebase-blaze-plan