Blog

2018.05.17

Tutorial: Use merge fields to pass users address to MailChimp via API without empty result. Problem solved

Recently I embarked on a journey to integrate MailChimp API with abandoned carts plugin. At first I thought that it should be a peace of cake since I saw their huge documentation, but I was mistaken and had to spend my whole afternoon digging google to understand why I am getting empty address field after everything else is imported. Just to be clear – I really like the new Mailchimp 3.0 API and they have done a beautiful job on the documentation but there still are some blind-spots.

From MailChimp documentation I found that when you are trying to add a new subscriber to one of your mailing lists you can use the “merge_fields” parameter to pass user related information like Name, Last name, Phone number and Address (this merge_fields cheat-sheet also came in handy). Passing all of these fields was quite easy except for Address field which didn’t register on MailChimp and every time returned an empty result (see screenshot below).

MailChimp API empty address fields

I tried multiple and various solutions to get this problem fixed (passing arrays, objects, strings etc.) until I turned to Google but it was really hard to find a good article that would help to fix this issue or explain how to pass Address field to MailChimp using merge_fields until I found a published email conversation that gave some explanation into how MailChimp is accepting Address field.

If you want to prevent Mailchimp returning empty Address field you have to pass 5 mandatory fields to it:

  • Address Line 1 (addr1)
  • City (city)
  • State (state)
  • Zip code (zip)
  • Country (country)

Unless one of these is left out, you will see empty column. Also I must add that none of these fields can be left blank even if you do not need or have some of those values replace it with “n/a” or similar.

Here is the working solution and end result of passing Address field to MailChimp via API:

After this I was finally able to get Address fields over to MailChimp. I hope this tutorial helps to save time and money for others in the same spot as I found myself one day :). Please comment below if you have some additional information to add.

In categories: Tutorials, Website development

Nauris Kolāts

Nauris is a freelance designer / developer who loves to dig into the UX as much as in the ground for fishing worms. And fishing is just one amongst the long list of his active lifestyle hobbies.

Other posts

Your thoughts

Join the discussion

  1. Anja

    hello,
    Thank you for sharing your new found knowledge. I have the same question but for a ‘date’ field. Recently I added a ‘date’ field to my list. I imported a new list (including a column with dates) but the column ‘date’ in my list in MailChimp remained empty. Do you maybe have a suggestion to fix this problem?
    Thank you in advance!

    • Hey Anja,

      Thanks for your question.
      If I understand you correctly, you are importing members into a list.
      From this MailChimp API page here: https://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/ you can see that MailChimp says that date fields must be in a specific format.

      The date and time the subscribe confirmed their opt-in status in ISO 8601 format.

      So I would suggest you to double check the date format you have in your list prior to importing it to MailChimp.
      If the date field is not in the correct format, it will most probably be left blank.

      By the way you should check MailChimp API log file (under mailchimp.com/account/api/) after the import – there you could try to find some additional info about what is wrong with the import. It should be visible under “Last 24 hours of API calls“.

  2. Adrian

    Thank you so much for that information. I haven’t found anything about this anywhere else. This saved me a lot of headache!

    • Your welcome, Adrian. Was struggling with this a lot myself therefore decided that this could help others in need as well. MailChimp API documentation has a lot to improve – huge amounts of information but in many cases very difficult to find what is necessary.

  3. Mark

    Ahhhhh, thank you so much! Trying to pass those fields was kicking my butt. You saved the day.

    • Heh, glad to help another wondering soul on the web. I was stuck on it for some hours as well until I figured it out :)

  4. Jason P.

    Thank you for posting this. I search for a while and finally found this page. It solved my issues. Thank you!

  5. Jérémy LEBEL

    Hi,

    First, thanks a lot for your useful article. I agree that the official doc lacks crucial information. I have encountered a similar issue i wish to share with you.

    I was adding a first time the address on members API with a specific merge field address.
    It works like a charm, but after adding an order to the member using order API, the address always desappeared…
    I have tried your hack but it was not enough.

    After many tries, I just found the solution.

    When I add an order, I have to add the address on customer. But not in the merge field, just in the address field.

    Be careful because the fields are not the same…
    MEMBER CUSTOMER
    addr1 address1
    addr2 address2
    state province
    zip postal_code

    Member :
    [merge_fields] => Array
    (
    [ADDRESS] => Array // ADDRESS is the alias i give to my merge field
    (
    [addr1] => 10, rue de la Liberté
    [addr2] =>
    [city] => Paris
    [state] => n/a
    [zip] => 75000
    [country] => France
    )
    )

    Customer (on order or cart API) :
    [address] => Array
    (
    [address1] => 10, rue de la Liberté
    [address2] =>
    [city] => Paris
    [province] => n/a
    [postal_code] => 75000
    [country] => France
    [country_code] => FR [optionnal]
    )

    Maybe this would help someone…

    Best regards

    • Thanks for your input, this might help others down the line :)

  6. Jag

    Hi Nauris,

    I’m trying to integrate Mailchimp with Microsoft Dynamics. I’m able to create a new contact in Dynamics when someone signups to the newsletter in Mailchimp.

    Any ideas how I can trigger an event when a member update his/her contact details or group using the mailchimp update preference so I can push the update details to Microsoft Dynamics.

    • Hi Jag,

      I would love to help however I have little or maybe none knowledge on Microsoft Dynamics :)

Latest work