Skip to content

Instantly share code, notes, and snippets.

@bettysteger
Last active October 4, 2018 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bettysteger/3837cc3966ff7a89fb7a12b6ab73c8ea to your computer and use it in GitHub Desktop.
Save bettysteger/3837cc3966ff7a89fb7a12b6ab73c8ea to your computer and use it in GitHub Desktop.
Add mailchimp subscriber on Firebase user signup (firebase function)
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
});
{
"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
}
@bettysteger
Copy link
Author

In case the log of the Firebase Function says:

Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions

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

The Firebase Blaze plan is a "pay as you go" plan, as indicated on the Firebase pricing page. It is a post-billing service, meaning that you get billed for your usage at the end of the month.

During the month, you can track your usage (and thus pricing) for the service in the Firebase Console.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment