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?
How to create list member with ADDRESS using Mailchimp API v3
Asked Answered
I am facing the same problem. I tried the address format documented for Customer in e-commerce stores and a plain text. Neither worked. –
Declination
I just love the Mailchimp API and docs. Company has been around for twenty years and their API docs are wretched. –
Ailee
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. –
Attrahent
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
Thank you! I've been searching this for hours! –
Spathe
I win, I was working on this for days. Thank you Mailchimp API docs! –
Sipes
This worked for me, but only when certain fields are not empty. I think the combination in my case was
addr1
, city
, zip
, and country
. –
Sepaloid @Sepaloid 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. –
Esbjerg
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,
],
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;
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. –
Yawp
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));
...
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': "[email protected]"})
#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)
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;
© 2022 - 2024 — McMap. All rights reserved.