If your account has multiple subscriber lists, the important first step is to ensure your script is operating on the right list.

MailChimp API identify each mail list with an unique ID. It's usually 10 characters long, mix of letters and numbers. However when you navigate to a list in MailChimp web console, the id field is only 6 digits:

The id field you see in the web console is known as the Web ID. It's not the actual ID of the list. You cannot make API requests using the Web ID. This is an unfortunate design in the MailChimp API. This post will help you find the real ID of your list by filtering through Web IDs.

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

Finding the Right List

Let's start with a list query to see what data is returned.


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

// Get "/lists"
const result = await api.get('/lists')
for (let list of result.lists) {
	console.log(`List: ${list.name} - ID: ${list.id} - Web ID: ${list.web_id}`)
}

The script should print the name, unique ID, and web ID of your subscriber lists. Alternatively, you can find the web ID through the MailChimp web console:

  • In MailChimp web console, navigate to your list of interest
  • In your browser URL field, copy the 6 digit id field, which is your Web ID
  • Paste the Web ID into line 5 of script below

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

// The Web ID of list you are trying to find. e.g. const webId = 123456
const webId = 0

// Get all "/lists" and filter by Web ID
const result = await api.get('/lists')
let myList = result.lists.find(list => {
	return list.web_id === webId
})

// Exit if no list is found
if (!myList) {
	console.log(`List with Web ID ${webId} not found`)
	return
}

// Print list info and subscriber count
console.log(`Found list ${myList.name} - ID: ${myList.id}`)

const { member_count, unsubscribe_count } = myList.stats
console.log(`Subscribers: ${member_count - unsubscribe_count}`)