The ADDRESS is a Merge Field but the documentation (http://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/) is not clear on how to pass it to the API, since it has sub fields for street, zip, city etc. Does anybody have an example how to do this?
Asked
Active
Viewed 6,918 times
13
-
I am facing the same problem. I tried the address format documented for Customer in e-commerce stores and a plain text. Neither worked. – Patrik Beck May 30 '17 at 13:53
-
1I just love the Mailchimp API and docs. Company has been around for twenty years and their API docs are wretched. – evolross Feb 08 '20 at 01:52
-
Be aware that setting the address in a CSV import as a string *does* work, but setting it in the API as a string *does not* - use the solutions to this question as a guide for the latter. – Scott C Wilson Jun 09 '20 at 18:07
6 Answers
24
This JSON works:
{
"addr1" : "first line",
"addr2" : "second line",
"city" : "city",
"state": "state",
"zip": "zip code",
"country": "country"
}
It's documented in schema here: https://us1.api.mailchimp.com/schema/3.0/Lists/Members/MergeField.json

Patrik Beck
- 2,455
- 1
- 19
- 24
-
-
1
-
1This worked for me, but *only* when certain fields are not empty. I think the combination in my case was `addr1`, `city`, `zip`, and `country`. – ACJ Feb 10 '20 at 21:30
-
@ACJ Mailchimp also requires the state field for US address as well as various countries (like China, Italy, Greece, Canada, etc). They don't seem to document for which countries the state field is required, but there are definitely many that do require it. Interestingly the schema file referenced seems to indicate that the state field is required for all addresses, though it does not seem to be enforced for certain countries. – nextgentech Feb 26 '20 at 20:51
4
Merge fields can pass like this:
'FNAME' => $contact->first_name,
'LNAME' => $contact->last_name,
'ADDRESS' => (Object)[
'addr1' => $contact->fulladdress,
//'addr2' => $contact->address2,
'city' => $contact->city,
'state' => $contact->state_region,
'zip' => $contact->zip_postal_code,
'country' => $contact->country->shortcode,
'language' => $contact->language->code,
],

Adiyya Tadikamalla
- 893
- 10
- 8
4
Just in case someone runs into the same problem.
I created my own address-class and tried to set the ADDRESS
-MergeField to a JSON-string as follows:
member.MergeFields["ADDRESS"] = Newtonsoft.Json.JsonConvert.SerializeObject(MyAddressObject);
This does not set the address, but also returns no error.
One need to assign a Dictionary<string, object>
instead:
var adr = new Dictionary<string, object>
{
{ "addr1", "123 Whatever" },
{ "addr2", "" },
{ "city", "New York" },
{ "state", "NY" },
{ "zip", "12345" },
{ "country", "US" }
};
member.MergeFields["ADDRESS"] = adr;

Scott C Wilson
- 19,102
- 10
- 61
- 83

MatSnow
- 7,357
- 3
- 19
- 31
-
The first issue can be fixed by just passing the MyAddressObject to the MergeFields["ADDRESS"] instead of serializing it. The reason is that the member will be serialized when calling the API and the address object will automatically be serialized too. – Bruno V Dec 20 '22 at 14:29
3
It works for me (php)
$address = new stdClass();
$address->addr1 = $customer->address;
$address->city = $customer->city;
$address->state = $customer->state;
$address->zip = $customer->zip;
$address->country = $customer->country;
$options = [
'status' => 'subscribed',
'email_address' => $customer->email,
'merge_fields' => [
'FNAME'=> $customer->first_name,
'LNAME'=> $customer->last_name,
'PHONE' => $customer->phone,
'ADDRESS' => $address,
]
];
...
curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($options));
...

Kammex
- 31
- 2
1
Python answer
I was getting error's because address line 1 was empty. Here's a copy and paste code that works:
added_user= {}
added_user.update({'email_address': "ground0@yahoo.com"})
#status options: "subscribed", "unsubscribed", "cleaned", "pending", or "transactional"
added_user.update({'status': 'subscribed'})
address_dict = {
"addr1": "line 1",
"addr2": "made up address",
"city": "Kirkland",
"state": "WA",
"zip": "12345",
"country": "US",
"language": "en"
}
added_user.update({'merge_fields':{ 'FNAME': "Corona",'LNAME': "Virus", 'ADDRESS':address_dict}})
client.lists.members.create(list_id=list_id,data=added_user)

Brad123
- 877
- 10
- 10
1
You can create your own Address Class and assign it as follows
public class Address
{
[JsonProperty("addr1")]
public string Address1 { get; set; }
[JsonProperty("addr2")]
public string Address2 { get; set; }
[JsonProperty("city")]
public string City { get; set; }
[JsonProperty("state")]
public string State { get; set; }
[JsonProperty("zip")]
public string Zip { get; set; }
[JsonProperty("country")]
public string Country { get; set; }
}
var address = new Address()
{
Address1 = "1 Main Street,
Address2 = "",
City = "Brooklyn",
State = "NY",
Zip = "11299",
Country = "US"
};
member.MergeFields["ADDRESS"] = address;

Sol Fried
- 11
- 1