mailchimp-api icon indicating copy to clipboard operation
mailchimp-api copied to clipboard

mailchimp objects

Open giorg opened this issue 8 years ago • 4 comments

Hello,

I'm able to send data to mail chimp for text fields, but how can I format data for those which mailchimp calls "object"? Like address, or product in case of order?

Thanks a lot

giorg avatar Dec 06 '16 16:12 giorg

@giorg you'll need to read the mailchimp api docs for this. Try: http://developer.mailchimp.com/documentation/mailchimp/guides/get-started-with-mailchimp-api-3/#json

Insti avatar Dec 13 '16 10:12 Insti

thanks for your answer, yes I've read that, I mean I tried the usual way in php:

$result = $MailChimp->patch("lists/501580b9e9/members/$subscriber_hash", [ 'merge_fields' => [ 'FNAME' => $order->getCustomerFirstname(), 'LNAME' => $order->getCustomerLastname(), 'BSTREET' => $baddress[0], 'BCITY' => $order->getBillingAddress()->getCity(), 'BPOSTCODE' => $order->getBillingAddress()->getPostcode(), 'BADDRESS' => array( 'address1' => $baddress[0], 'city' => $order->getBillingAddress()->getCity(), 'province' => $order->getBillingAddress()->getRegion(), 'postal_code' => $order->getBillingAddress()->getPostcode(), 'country_code' => $order->getBillingAddress()->getCountry() ) ] ]);

but the BADDRESS gives me "merge field invalid", if I remove it everything works. So I wonder how to format the BADDRESS field.

thanks a lot

giorg avatar Dec 13 '16 11:12 giorg

The address data structure looks like this:

[
    'addr1'   => '',
    'addr2'   => '',
    'city'    => '',
    'state'   => '',
    'zip'     => '',
    'country' => ''
]

maff avatar Dec 22 '16 13:12 maff

Just in case anyone is still looking around for this answer here is what the code should look like:

$subscriber_hash = $MailChimp->subscriberHash($email);
$result = $MailChimp->patch("lists/$list_id/members/$subscriber_hash", [
                'merge_fields' => [
                'FNAME'		=>	$firstname, 
                'LNAME'		=>	$lastname, 
                'ADDRESS'   => array
			(
			 'addr1'   => $addline1,
			 'addr2'   => $addline2,
			 'city'    => $city,
			 'state'   => $state,
			 'zip'     => $zip,
			 'country' => $country
			)
                ],
                'interests'    => [$interest_id => true],
            ]);
print_r($result);	

wfinley avatar Feb 01 '17 02:02 wfinley