Display all items in the terminal with mailchimp API in javascript

179 Views Asked by At

I'm using mailchimp to display all my email address from an audience, to do so, I'm using this code:

const client = require("@mailchimp/mailchimp_marketing");

client.setConfig({
apiKey: "MY API KEY",
server: "MY SERVER",
});

const run = async () => {
const response = await client.lists.getListMembersInfo("LIST MEMBERS CODE");
i = 0
while (i < response.members.length){
   finalObject = Object.values(response.members[i]);
   console.log(finalObject[1]);
   i++
   }
};

run();

"MY API KEY", "MY SERVER" and "LIST MEMBERS CODE" are fake one here, I have the real ones in my code.

My problem is that the terminal only display 10 items, and I have 1058 total_items . I know that the problem is count that is 10 by default but I don't know how to change it because I don't have any URL to call the API.

Is there any other way to display all items by changing the number of count ?

I also know that the maximum items to display is 1000 so I have to do it twice to display all 1058 items.

1

There are 1 best solutions below

0
PeterKA On

Examination of the relevant method here indicates that you can supply a second parameter, an object. In your case, it would be:

{'count': 1000}

Thus the call would be:

const response = await client.lists.getListMembersInfo("LIST MEMBERS CODE", {'count': 1000});

See MailChimp API Reference for more parameters.