Sample application to show how to add subscribers to a MailChimp list using nodeJS. It took me a few hours finding how to do this, piecing together from their documentation, some answers, debugging and reading the source code, so I decided to put together this repo to make it easier for others.
Replace the values in config.js with your API key and list id so you can experiment
with this code. This is a regular express application, run npm i and npm start and
navigate to localhost:8000.
The code you need to use in your application is on mc/index.js. The example included uses
the endpoint to add a subscriber, but those are the same principles to use any other endpoint,
like getting subscriber info, or updating their information.
For more information on the mailchimp api check out the official Mailchimp documentation, or in the documentation for the API wrapper we're using.
Checkout the code on this commit to see exactly what you need e0283b6.
To find or generate an API Key go to your account settings > Api Keys, as described here.
The list id is not the id on the query parameters when you look at your subscribers, you have to go to the list settings > list name and defaults, and close to the list name you'll see the list id. As detailed here.
Always keep your API key and List ID private, if you share them with anyone they will potentially have access to all your subscribers's information and information about your account. And ill intentioned people can use this information to damage your brand's reputation or delete your subscribers to mess with you.
Always use different API keys for every application, and give separate ones to your collaborators, MailChimp gives you an option to invalidate keys so you can revoke access to people when they no longer need it.