Passing address field to lists/subscribe using the MailChimp API 2.0 isn't working

StackOverflow https://stackoverflow.com/questions/21833001

  •  12-10-2022
  •  | 
  •  

سؤال

I'm using the following code to add an email address to a list in MailChimp. All fields are sending through correctly except ADDRESS, which is just empty when I look in MailChimp.

I'm using the format described here which tells me that I can pass a string with each piece of the address separated by two spaces.

$this->mc = new Mailchimp('{api key here}');
$address = array(
    'Line 1',
    'Line 2',
    'Line 3'
);
$this->mc->lists->subscribe('{list ID here}', array('email' => '{email here}'),array(
    'MMERGE6' => $title,
    'FNAME' => $first_name,
    'LNAME' => $surname,
    'ADDRESS' => implode('  ',$address),
    'TOWN' => $town,
    'POSTCODE' => $postcode,
    'COUNTRY' => $country,
    'MMERGE7' => $organisation,
    'MMERGE8' => $role,
    'MMERGE10' => $source, 
    'MMERGE11' => (!empty($newsletter) ? 'Yes' : 'No')
));

What am I doing wrong?

هل كانت مفيدة؟

المحلول

You mentioned in your comment that you've switched to the array syntax, so this may not be helpful to you, but in case anyone else cares.


I was able to replicate the issue - passing "Line 1 Line 2 Line 3" (two spaces between each value) wasn't populating my address field as expected. After a bit of fidgeting and comparing with how address fields are formatted when I export my MailChimp list to a CSV file (in the app), it looks like the API call is expecting five values, each separated by two spaces.

So, to make the original code work, send an array like so:

$address = array('Line 1', 'Line 2', 'Line 3', 'Line 4', 'Line 5')

I imagine this five value syntax is to ensure it fills the Street Address, City, State, Zip, and Country fields, for the Address.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top