Auth0 MailChimp Export

Hi community!

I’m looking to export my users dynamically to Mailchimp throuhg a rule. Just like done here towards intercom.

This is one simple rule. However, it doesn’t seem to work for me…

Can someone help me out?

Thank you!

Best regards,
Thomas

Hi @ThomasTBG,

Welcome to the Community!

Can you tell us how it is not working? What errors are you seeing from the request?

Hi Dan!

Thank you for your quick reply.

And sorry for not being very specific here :upside_down_face:

I’m trying to setup a referral scheme after inspiration from Automate All the Things (No code referral marketing program with Webflow, Airtable and Zapier [part 1] - YouTube)

I’ve found out that the testing of the rule within Auth0 didn’t work, but the live version does now! So good news there.

However, I’ve got two questions where you might be able to help me…

  1. How can I make sure that all the data is transfered into mailchimp? At the moment, with this coding (LINK) only the email address is saved into Mailchimp. And I’d actually like to do something like this:
    const ctx = {
    email_address: user.email,
    merge_fields : {“FNAME”: user.given_name || “”,
    “LNAME”: user.family_name || “”},
    user_id: user.user_id,
    name: user.name,
    signed_up_at: moment(user.created_at).unix(),
    last_seen_ip : context.request.ip,
    last_seen_user_agent: context.request.userAgent,
    update_last_request_at: true,
    new_session: true
    status: “subscribed”
    };
  2. Furthermore, everyone signing up throuhg Auth0 has Metadata of their referral email address (‘ref’) stored. How can I get this ‘ref’ information in Mailchimp?. I’ve created an input field named REF in mailchimp and this is my custom code in the Auth0 rule under ‘const ctx’
    “custom_attributes” : {
    “ref” : user.user_metadata.ref
    },
    But also this seems not to be uploaded into Mailchimp…

Would be SO GOOD if you could help me out, Dan :slight_smile:

Have a good day!

Best regards,
Thomas

Are you seeing error codes when you make the request to add this data mailchimp?

Hi Dan!

Thank you for your help!

I unfortunately don’t see any error codes in Mailchimp/Auth0. Where can I find those?

I’m dynamically/automatically (via API) trying to get the data from Auth0 into Mailchimp via a rule - written out below.

I can only see that the emailadress is saved into Mailchimp (succes!) but without any further data. In an ideal world I’d like to have the custom attribute data ‘ref’ in Mailchimp and that the status is subscribed (at the moment it is ‘cleaned’).

Thank you so much for looking into this.

Best regards,
Thomas

/*
*  Update a Mailchimp list with user emails during the signup or the first login.
*
*  Create the following atributes in the Auth0 RULE configuration settings.
*  https://auth0.com/docs/rules/guides/configuration
* 
*  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.: https://us20.api.mailchimp.com/3.0
*
**/
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 = {
        email_address: user.email,
        "custom_attributes" : {
      	"ref" :  user.user_metadata.ref
    		},
        merge_fields : {"FNAME": user.given_name || "",
                        "LNAME": user.family_name || ""},
        status: "subscribed"
    };
 
    var auth = "Basic " + new Buffer("token:" + configuration.MC_TOKEN).toString("base64");

    request.post({
      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);
}
1 Like

Hi @dan.woda,

I hope everything is going well on your side.

I’m sure you’ll be super busy at the moment, but just wanted to follow up with you to check if you’ve had a chance to look at my previous message. I understand this is not an easy one… I’d like to therefore ask you what bits of information you’d need from me in order to help me getting further here.

Just let me know! Very much looking forward to hearing from you.

Thanks a lot!

Best regards,
Thomas

1 Like

Hey there!

Dan was out of office but he should be back today so should get back to you! Thanks for understanding!

1 Like

Thanks so much. No worries! Looking forward to hearing from you.

1 Like

You can debug rules with a console.log and see the response from your post request. This should help you understand what is happening on the Mailchimp API side. It sounds like you are having a successful request, and maybe it is just ignoring some params.

I don’t see a custom_attributes param in the Mailchimp API docs for that request. Are you sure you are able to add that type of data to the user object in Mailchimp?

Hi Dan,

Thank you so much for all your assistance. I’ve found the solution with a friend. I was in the end looking for the following rule in Auth0 to get the data into 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.
*  https://auth0.com/docs/rules/guides/configuration
* 
*  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.: https://us20.api.mailchimp.com/3.0
*
**/
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 = {
        email_address: user.email,
        /*"custom_attributes" : {
      	"ref" :  user.user_metadata.ref
    		},*/
        merge_fields : {"FNAME": user.given_name || "",
                        "LNAME": user.family_name || "",
                        "REF": user.user_metadata.ref || ""},
        status: "subscribed"
    };
  
    console.log(user.user_metadata.ref);
 
    var auth = "Basic " + new Buffer("token:" + configuration.MC_TOKEN).toString("base64");

    request.post({
      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);
}

Very happy with the result!

Have a great day you all.

Best regards,
Thomas

Thanks for posting a solution! Glad you got it worked out.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.