Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Auth0 rule for sending emails of signed up users to Mailchimp.
* Update a Mailchimp list with user emails during the signup or the first login.
* Create the following atributes in the Auth0 RULE configuration settings.
* MC_TOKEN: Mailchimp API Token. E.g.: ef235a44355dda3e61ea074ae0d439a2-us20
* MC_LIST_ID: ID of the Mailchimp list you would like to populate. E.g.: ca9eb2555e
* MC_API_URL: Mailchimp API URL. E.g.:
function (user, context, callback) {
// Short-circuit if the user signed up already
if (context.stats.loginsCount > 1 || context.protocol === 'oauth2-refresh-token') {
return callback(null, user, context);
const request = require('request');
const ctx = {
merge_fields : {"FNAME": user.given_name || "",
"LNAME": user.family_name || ""},
status: "subscribed"
var auth = "Basic " + new Buffer("token:" + configuration.MC_TOKEN).toString("base64");{
url: configuration.MC_API_URL + "/lists/" + configuration.MC_LIST_ID + "/members",
headers : {"Authorization" : auth},
json: ctx
// Don’t wait for the Mailchimp call to finish, return right away (the request will continue on the sandbox)`
callback(null, user, context);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment