I'm using this code to get a list of members in an audience and put their email adresses in arrays:
var mailchimpMarketing = require("@mailchimp/mailchimp_marketing");
mailchimpMarketing.setConfig({
apiKey: "MY API KEY",
server: "MY SERVER",
});
async function getArrayEmailMembersFromMailchimpListID(listID, offset , count){
const response = await mailchimpMarketing.lists.getListMembersInfo(listID, {offset, count});
const emailsMailchimp = response.members.map(member => member.email_address);
console.log(emailsMailchimp)
return emailsMailchimp;
}
async function getEmailsAccordingSize(listID){
const response = await mailchimpMarketing.lists.getListMembersInfo(listID)
offset = 0
totalItems = await response.total_items
do {
count = 1000
getArrayEmailMembersFromMailchimpListID(listID, offset, count)
offset = offset + 1000
} while (offset < totalItems);
}
getEmailsAccordingSize("MY LIST ID");
My problem is when I'm making this to a very big list of members in an audience it return to me this error:
(node:8014) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Too Many Requests
(node:8014) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
I'm assuming I can only make 10 calls in a row. So how can I make more ? I have an audience with 37 000 members in it and I have to take all their emails adresses.
I don't understand the batches endpoint that are explain on mailchimp website (https://mailchimp.com/developer/guides/run-async-requests-with-the-batch-endpoint/). Is it possible to do it with batches ? How ?