Zapier’s Add/Update Subscriber Action for Mailchimp already provides the ability to Update Interest Groups for a Subscriber.
For most users - this is the preferred and easiest method for updating interest groups in Mailchimp.
However - some users have a large number of Interest Categories in Mailchimp.
When there are too many Interest Categories and Groups - the Zap might timeout when attempting to lookup the Interest Group by Category.
The error we might see when this happens in a live Zap Run is:
The app did not respond in-time. It may or may not have completed successfully.
In that case - we can still follow the steps below and use a Code Step and Webhooks by Zapier to update the Interest Groups on a Subscriber in Mailchimp.
What We Need from Mailchimp
There are 2 things we need from Mailchimp directly to make this work.
First - we want to follow Mailchimp’s Instructions for generating an API Key.
You can find those here.
And next - we want to take note of the URL we see when we are logged into Mailchimp.
The first part of this URL will be different for different users - and we’ll need that piece in our Webhooks step below.
Once we have those 2 pieces of data from Mailchimp - we’re ready to move on to our Zap.
Building Our Zap
I’m assuming that you already have a trigger that is providing the email address for an existing Subscriber we are wanting to update Interest Groups for.
And at this point we are just focused on how to make the Webhook request to Mailchimp to update the Groups.
Step 1 - Finding Our Mailchimp IDs
The first thing we need to do is add a test contact to Mailchimp with the Group ID’s we are wanting to update using the Add/Update Subscriber action in Zapier directly.
In the screenshot below - I’ve done the following:
-
Added a test email address that does not exist already in the Audience I want to update the Subscriber in
-
Chosen Add Only for the option on Replace Groups
-
Selected the 3 Groups I want this Zap to Add to the Subscriber when it runs live.
After we test the step above - we’ll see something like this:
The ID Codes with “true” next to them are the 3 Group IDs I selected in the Zap Editor.
Copy the IDs for the “true” values - as we will need those in our Webhooks Step below.
In my case the ID’s are:
9840e79490
7395033c08
9cfe128775
We also want to scroll down and get the List ID as well.
In my case this is bb8167e2be
Step 2 - Hash Our Email Address
When we make our Webhook request to Mailchimp - we have to translate our Email Address into its MD5 Hash equivalent - as this is what Mailchimp requires in the Webhook request.
To do that - we’re going to use a Code by Zapier (Javascript) action.
These Code steps are an advanced feature in Zapier - and beyond what our Support Team can help users with.
And I freely admit to borrowing that code below one of Zapier’s founders here. :)
To make that step above - you would use the same name for the input data section (email) - and then map in the email address from your previous step in the Zap.
Then just copy and paste the code below.
var crypto = require('crypto');
var emailStr = inputData.email;
var hashStr = crypto.createHash('md5').update(emailStr).digest('hex');
return {emailHash: hashStr}
When we run the test - we’ll see something like this.
The “emailHash” value is the MD5 Hash of my test email.
Step 3 - Configure our Webhook
Now we’re ready to put it all together and configure our Webhook to update the Interest Groups.
First - we want to choose Webhooks by Zapier as the action App - and then choose Custom Request as the Action Event.
Then we’d configure our Webhook like this.
Method: PUT
URL:
For the URL we are going to start with this template.
https://YOURURL.api.mailchimp.com/3.0/lists/YOURLIST/members/
You would replace “YOURURL” with the value you see from the URL when you login to Mailchimp. In my case this is “us5”.
And then you would also replace “YOURLIST” with the List ID we identified above. In my case this is “bb8167e2be”
So my final URL is:
https://us5.api.mailchimp.com/3.0/lists/bb8167e2be/members/
And I would then map in the MD5 Hash Value for the email address at the end of that.
Data:
You can copy and paste this as a template.
{
"email_address": "MAP_EMAIL_HERE",
"interests": {
"9840e79490": true,
"7395033c08": true,
"9cfe128775": true
}
}
You would replace my Group ID’s with the Group ID’s you identified in Step 1 above.
And also replace MAP_EMAIL_HERE with the email address mapped from your Zap.
If you need to add more or remove some - that is fine as well. Just make sure the last row does not have a comma at the end.
Headers:
We want to add 2 Headers.
“Content-type” with a value of “application/json”
AND
“Authorization” with a value of “Bearer YOURAPIKEY”
Where you would replace “YOURAPIKEY” with the API Key you generated in Mailchimp.
Testing the Webhook
To test this I’m going to make sure my test email doesn’t have any Groups in Mailchimp.
Then I’m going to run the test in Zapier.
Finally go back to check Mailchimp once the test completes.
And...Success!
The Interest Groups are now on the Subscriber in Mailchimp.
Questions
Will this work for New Subscribers that are being added to the list?
It will - but we’d want to add some additional fields to the request for it to work to add a New Subscriber.
I’ve hardcoded the values for email address and FNAME and LNAME below - but you would want to dynamically map that data from the previous steps of your Zap.
Can I use this to update fields other than Interest Groups?
Yes - similar to the example above - we can update additional fields this way as well.
However this could get complex quickly.
You can find Mailchimp’s documentation for this Endpoint here.
And testing from a 3rd party tool like Postman is always advisable to make sure your requests are working outside of Zapier first.
Summary
When we need to update Interest Groups on a Subscriber in Mailchimp - we’d normally do this using the Add/Update Subscriber action.
For some users with a large number of Interest Categories and Groups - this action might timeout - causing an error in the Zap Runs.
We can still update the groups using a Code Step to Hash the email address and a Webhooks by Zapier action to send the request to Mailchimp.
Both Code and Webhooks are advanced features in Zapier - and our Support Team isn’t usually able to help with the exact format of the Code or Webhooks Request.
If you do give this a try - I’d love to hear your experience in the comments below!