Intro to MailChimp API 3.0: Adding Members to a Mailing List and testing with Postman

Denise Ortega
3 min readJun 13, 2017

--

Gather the following information:

From your MailChimp account

From the MailChimp List you created

We’ll be using the following MailChimp API routes:

  1. base/test connection: GET https://<dc>.api.mailchimp.com/3.0/

2. add to mailing list:POST https://<dc>.api.mailchimp.com/3.0/lists/<list_id>/members/

3. check if email is part of mailing list:GET https://<dc>.api.mailchimp.com/3.0/lists/<list_id>/members/<member_id>

Let’s Start!

For this example I’ll use the following values:

  • list_id = 123456
  • api_key = myfakeapikey11294814-us15
  • dc = api_key.split("-")[1]= us15

Test the base API call

Let’s test that we can connect to the MailChimp API and get a successful response by sending a GET request to the base URL. I’ll be using Postman to test all the routes.

Replace the <dc> in the base URL with your dc. My dc is us15, so theURL will look like this:

https://us15.api.mailchimp.com/3.0/

You’ll also need to use your API key to access the API. In Postman under the Authorization tab choose Basic Auth . Under username you can put any string (the MailChimp docs suggest using anystring). The password should be your API key. In my case it’s myfakeapikey11294814-us15

Hit Send and if the response was successful, you should see an object returned with your account information

Add a member to your Mailing List

Now that we’ve successfully connected to the API, let’s make a call to add a member to our Mailing List. To do this, we’ll make a POST request to the https://<dc>.api.mailchimp.com/3.0/lists/<list_id>/members/ URL.

I’ll replace dc and list_id with my values to get the following URL:

https://us15.api.mailchimp.com/3.0/lists/123456/members/

I’ll also need to pass in a JSON object with information about the new member. For my list, I’ve created the following fields:

  • email_address (by default all lists must this)
  • FIRSTNAME
  • LASTNAME

You can edit the expected and mandatory fields by clicking on the Settings → List fields and *|MERGE|* tags tab of your list

My list expects email_address, FIRSTNAME, and LASTNAME

Your object must also include a status field. The status field can have any of the following values:

  • subscribed
  • unsubscribed
  • cleaned
  • pending
  • transactional

For this example we’ll use subscribed which will just add a new member to the list. You can learn more about the other status fields here.

I’ll add Spongebob Squarepants to my list. Your request body should look like this:

Don’t forget to add the authorization information like we did in the base URL example.

Once you send the request, you should know if it’s successful if JSON resembling the new member is returned. Other ways to check if it was successful are by checking the List in MailChimp or doing another API call with the new Member’s id. Let’s do that next.

Verify the member was added

Send a GET request to the following URL: https://<dc>.api.mailchimp.com/3.0/lists/<list_id>/members/<member_id>

The dc and list_id are the same as before (us15 and 123456 respectively). The member_id is the md5 hash of the member’s email address.

md5(sponge@bob.com) → cc1fd70c2267537857c5a2b94396aa39

You can find the member_id by looking at the id returned by the POST request we executed above, or you can get the hash by plugging in the member’s email address here.

Now the URL should look like this: https://us15.api.mailchimp.com/3.0/lists/123456/members/cc1fd70c2267537857c5a2b94396aa39

Sending the request should return an object with the member’s information in it. You should be able to see the email_address, FIRSTNAME, and LASTNAME attributes that were supplied in the POST request.

If the email doesn’t exist in the mailing list, you will get a 404 Error: Resource Not Found.

--

--