Philipp Mochine
Philipp Mochine

Reputation: 4705

How to add/put address with MailChimp API?

I just cannot add an Address with the API. I managed to update every other column type, but not the address one.

I tried two ways:

$array['ADDRESS']['addr1'] = 'Amara Locks 12588'
...

But this approach didn't work. I got the error message:

400: The resource submitted could not be validated. For field-specific details, see the 'errors' array.

Because of this post I thought I needed to convert it to JSON. It worked for not getting any errors, but the field address stays empty in MailChimp.

Just for an example how the array looks like:

["ADDRESS"]=>
string(124) "{"country":"DE","addr1":"Amara Locks 12588","addr2":"Second Floor","state":"North Dakota","city":"East Kadin","zip":"33183"}"

Upvotes: 1

Views: 1205

Answers (2)

Hassan Tahir
Hassan Tahir

Reputation: 132

@Philipp Mochine answer is correct.This answer is for all those PHP developer who are 
looking for complete array structure.
array:2 [
"email_address" => "[email protected]"
"merge_fields" => array:4 [
"FNAME" => "Hassan"
"LNAME" => "Tahir"
"PHONE" => ""
"ADDRESS" => array:6 [
  "addr1" => "81 street"
  "addr2" => "house no 2"
  "city" => "Lahore"
  "state" => "Punjab"
  "zip" => "54000"
  "country" => "Pakistan"
]]
]

Upvotes: 0

Philipp Mochine
Philipp Mochine

Reputation: 4705

So for future readers. Yes the first way was the correct one. But my problem was that some of the values were null, so you need to remove them, e.g.

 $array['ADDRESS']['addr1'] = $address ?? '';

Upvotes: 1

Related Questions