Your list has tens of thousands of subscribers, but the GET call only returns 500...

This is because MailChimp API has a hard limit on how many items it could return in a single call. It is designed to prevent a bulk request from timing out, or worse, bringing down the API server.

Fortunately MailChimp API has a specific endpoint for dealing with bulk requests. You will see it refered to in the documentation as the Batch Operations or the Batch API.

The batch API is a smart work queue, that will break you API requests into smaller chunks, run them in parallel, and send back the result in compressed format.

If this is your first time working with MailChimp API, please consider reading the introductory post: Getting Started with MailChimp API


Getting the API Key

Before we start, let's get the access token of your MailChimp account.

Authorize with MailChimp

Hello, Batch Operations!

To make a batch operation request, wrap the request in the form of:

{
    method: "get",
    path: "/api/path...",
    query: { query_param: "xx" }
}

method refers to the HTTP request method, which is get for reading data. path is the API request path you would construct for a regular call. query is the additional query parameters.

Here is an example of how to bulk query list subscribers using the batch API.


const MailChimp = require('mailchimp-api-v3')
const api = new MailChimp(process.env.MAILCHIMP_API_KEY)

// Get all "/lists"
let result = await api.get('/lists')
if (result.lists.length === 0) return

// Get the first list result
const list = result.lists[0]
console.log(`Using List: ${list.name} - ID: ${list.id}`)

// Batch get list subscribers
result = await api.batch({
	method: 'get',
	path: `/lists/${list.id}/members`,
	query: { count: 200 }
}, { verbose: false })
console.log(result.members)

When you run the script above, it might take over 30 seconds to complete. It is going to be noticeably slower than making a direct API call. However it will not timeout no matter how big the request is. Try tweak the code above by setting { verbose: true }.