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…
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”
};
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…
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);
}
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.
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?
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);
}