Jhut89/Mailchimp-API-3.0-PHP

Passing language to the subscribed user

pks891618 opened this issue · 8 comments

How can we send the language for the particular subscribed user ?

I am trying to set the language but its not working

$post_params = [
"merge_fields" => [
'FNAME'=>$customer_data->getData()['First_Name'],
"LNAME"=>$customer_data->getData()['Last_Name'],
"KLANTNAAM"=>$account_data->getData()['Account_Name'],
"KLANTNR"=>$account_data->getData()['Klantnummer'],
"INDUSTRIE"=>$account_data->getData()['Industry'],
"TOER"=>$account_data->getData()['Toer'],
"tags"=>$tags,
"language"=>"nl",
'status'=>'subscribed',

	]
];

//post /patch data to the mailchimp and subscribe to the data
$mailchimp
->lists(LIST_toer)
->members($email_id)
->put($post_params)->deserialize();

It looks like language is nested in the merge fields above and in the documentation its a top level param. I have been on vacation but will try setting the language for a subscriber in my test account when I get home.

Hey there! 👋

I was able to successfully set the language of a contact using the following code:

$mailchimp
    ->lists('1a2b3c4d')
    ->members('0001@mailchimp.com')
    ->put([
        'email_address' => '0001@mailchimp.com',
        'status' => 'subscribed',
        'language' => 'en'
    ]);

This successfully update the contact's language to english. I was able to verify this in the test account I made the request against. As well as in the response body I received from Mailchimp.

{
	"id": "f2e007e423e4d49559dfa9375dfde6b1",
	"email_address": "0001@mailchimp.com",
	"unique_email_id": "1a2b3c4d",
	"email_type": "html",
	"status": "subscribed",
	"merge_fields": {
		"FNAME": "Example",
		"LNAME": "Person",
		"ADDRESS": {
			"addr1": "101 Some Place",
			"addr2": "Unit 101",
			"city": "Atlanta",
			"state": "Georgia",
			"zip": "999999",
			"country": "US"
		},
		"PHONE": "555555555"
	},
	"stats": {
		"avg_open_rate": 0,
		"avg_click_rate": 0
	},
	"ip_signup": "",
	"timestamp_signup": "",
	"ip_opt": "127.0.0.1",
	"timestamp_opt": "2019-03-26T19:22:33+00:00",
	"member_rating": 2,
	"last_changed": "2019-03-26T19:25:49+00:00",
	"language": "en",
	"vip": false,
	"email_client": "",
	"location": {
		"latitude": 0,
		"longitude": 0,
		"gmtoff": 0,
		"dstoff": 0,
		"country_code": "",
		"timezone": ""
	},
	"tags_count": 0,
	"tags": [],
	"list_id": "1a2b3c4d",
	"_links": [...]
}

I think perhaps the problem you are seeing is that you have nested the language index into your merge fields.

I'm going to go ahead and close this issue out, but please let me know if are still having difficulties. 😃

Sorry for late response was busy with some work

"merge_fields" => [
'FNAME'=>$customer_data->getData()['First_Name'],
"LNAME"=>$customer_data->getData()['Last_Name'],
"KLANTNAAM"=>$account_data->getData()['Account_Name'],
"KLANTNR"=>$account_data->getData()['Klantnummer'],
"INDUSTRIE"=>$account_data->getData()['Industry'],
"TOER"=>$account_data->getData()['Toer'],
"tags"=>$tags,
"language"=>"nl",
'status'=>'subscribed',

]

];
//post /patch data to the mailchimp and subscribe to the data
$mailchimp
->lists(LIST_toer)
->members($email_id)
->put($post_params)->deserialize();

what need to be changed in this code for updating the language ?

Sure thing. Currently your code looks like this:

$post_params = [
            "merge_fields" => [
                'FNAME'=>$customer_data->getData()['First_Name'],
                "LNAME"=>$customer_data->getData()['Last_Name'],
                "KLANTNAAM"=>$account_data->getData()['Account_Name'],
                "KLANTNR"=>$account_data->getData()['Klantnummer'],
                "INDUSTRIE"=>$account_data->getData()['Industry'],
                "TOER"=>$account_data->getData()['Toer'],
                "tags"=>$tags,
                "language"=>"nl",
                'status'=>'subscribed',
            ]
        ];

You can see the language, status and tags indexes are nested inside of merge_fields. They need to be their own top level index like this:

$post_params = [
            "merge_fields" => [
                'FNAME'=>$customer_data->getData()['First_Name'],
                "LNAME"=>$customer_data->getData()['Last_Name'],
                "KLANTNAAM"=>$account_data->getData()['Account_Name'],
                "KLANTNR"=>$account_data->getData()['Klantnummer'],
                "INDUSTRIE"=>$account_data->getData()['Industry'],
                "TOER"=>$account_data->getData()['Toer']
            ],
            "language"=>"nl",
            "status"=>"subscribed",
            "tags"=>$tags
        ];

Also don't forget that the email_address is required.