javascriptnode.jsmailchimpmailchimp-api-v3

How to diplay all elements with one request in javascript with mailchimp API


I'm calling the API mailchimp to get à list of members and I display all email address of my members by using this code:

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


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


const run = async () => {
  const response = await client.lists.getListMembersInfo("LIST ID");
  for (element of response.members){
    arrayObject = Object.values(element);
    console.log(arrayObject[1]);
 };
};

run();

"MY API KEY", "MY SERVER" and "LIST ID" are fake, I have the real one in my code.

My problem is that only the 10 first email address are display but I have 1058 email address in total. I can make 105 other request to get the 1058 total email address but I don't know how to do it. I also don't know how to change the count parameter because I don't use a URL to call my API.

So, how can I display all items in my terminal ?


Solution

  • If you go through the git repository you can see that the getListMembersInfo method takes a second parameter where you can specify the count

    const response = await client.lists.getListMembersInfo("LIST ID", { count: 100 });