Hi @CCDNB
Good question.
Are you trying to have a new word and QR code generated for each Mailchimp Subscriber whenever a Campaign is scheduled in Mailchimp?
Hi @Troy Tessalone Yes, that’s exactly what I’m trying to do.
I now have this figured out until Action 4:
Action 4: Update Subscriber
This final step has been very hard for me to implement.
@CCDNB
That’s going to be very “costly” to do as the # of subscribers grows.
Retrieving subscribers from the Mailchimp API involves pagination that need to be looped thru. (e.g. max 1,000 records per page.)
Mailchimp API supports BATCH operations. (read more)
FYI: The Looping app only supports a max of 500 records.
Zap action steps also have timeouts you need to work around. (e.g. max 30 seconds)
If you need help, consider hiring a Certified Zapier Expert: https://zapier.com/experts/automation-ace
@Troy Tessalone I’ve actually sorted it all out with Code, removing the loop function all together.
Action 3, retrieving the whole list of subscribers,
import requests
def retrieve_subscribers():
api_key = '***'
list_id = '***'
url = f'https://*.api.mailchimp.com/3.0/lists/{list_id}/members'
headers = {
'Authorization': f'Bearer {api_key}',
'Content-Type': 'application/json'
}
response = requests.get(url, headers=headers)
response_data = response.json()
return response_dataj'members']
subscribers = retrieve_subscribers()
return subscribers
And my Action 4 currently looks like:
const previousStep = {
password: 'generated_password_here',
qrCodeUrl: 'generated_qr_code_url_here'
};
const apiKey = '***';
const listId = '***';
const updateSubscriber = async (subscriber, password, qrCodeUrl) => {
const url = `https://*.api.mailchimp.com/3.0/lists/${listId}/members/${subscriber.subscriberId}`;
const mergeFields = {
WORD: password,
QR_CODE: qrCodeUrl
};
const response = await fetch(url, {
method: 'PATCH',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
merge_fields: mergeFields
})
});
const responseData = await response.json();
return responseData;
};
const subscribers = Array.isArray(inputData) ? inputData : sinputData]; // Ensure inputData is an array
const updatedSubscribers = D];
for (const subscriber of subscribers) {
const password = previousStep.password; // Access the generated password from the previous step
const qrCodeUrl = previousStep.qrCodeUrl; // Access the generated QR code URL from the previous step
const updatedSubscriber = await updateSubscriber(subscriber, password, qrCodeUrl);
updatedSubscribers.push(updatedSubscriber);
}
return updatedSubscribers;
HOWEVER While I have this code ^ I am unsure what to do with it…
The data being collected is the Word, QR Code, and List of Subscribers. I am unsure where to inout them properly into this code to make it work properly.
@CCDNB
Make sure to review the available help articles for using the Code app in Zaps: https://zapier.com/apps/code/help
Requiring or Using External Libraries
Unfortunately you cannot require external libraries or install or import libraries commonly referred to as "npm modules".
Only the standard node.js library and the fetch
package are available in the Code app.
fetch
is already included in the namespace.
@Troy Tessalone
I’ve been trying to batch mailchimp stuff you linked to. Do you know why it’s timing me out after 10.1 seconds? Mailchimp says it should be 120.
I just wanted to say that I completed this solo talking it over with ChatGPT. ChatGPT helped me way more than a real person did.
Thanks for following up here to let us know how you solved it @CCDNB. Presumably ChatGPT was able to rewrite the code you were using to fix things here?
At any rate, I’m glad you were able to find a solution here using ChatGPT. Gosh, is there anything it can’t do?!
Sounds like you’re all set for now but please do reach out in the Community if you ever need help. We’d love to hear from you!
@CCDNB
A more efficient approach may be to use Mailchimp exports and imports to prep and update the Subscriber data.
https://mailchimp.com/help/view-export-contacts/
https://mailchimp.com/help/import-contacts-mailchimp/
It seems that exporting from mail service defeats the purpose of Zapier. That is what I’m trying to save time on.
@CCDNB
A more efficient approach may be to use Mailchimp exports and imports to prep and update the Subscriber data.
https://mailchimp.com/help/view-export-contacts/
https://mailchimp.com/help/import-contacts-mailchimp/
It seems that exporting from mail service defeats the purpose of Zapier. That is what I’m trying to save time on.
I just retrieved the emails in batches though Python Code. It organizes them into a long row of data for the output, which I used as Input Data and split in a later step.
Here’s the code: https://chat.openai.com/share/1814131f-ce1c-4f65-a613-f1f781f3c56d