tiagovareta
Member
Hi,
I have a list button (php list plugin), to synchronize the list records, in the MailChimp list.
It is working, but only synchronizes the 1st selected record.
I have the following code:
$app = JFactory::getApplication();
$ids = $app->input->get('ids', array(), 'array');
foreach ($ids AS $myid)
{
$row = $model->getRow($myid);
$email = $row->tb_contactos_geral___email_login_ctg;
$nome = $row->tb_contactos_geral___nome_ctg;
$apelido = $row->tb_contactos_geral___apelido_ctg;
$status_ori = $row->tb_contactos_geral___status_ctg;
$status = "subscribed";
$apiKey = 'myapikey';
$listId = 'mylistid';
$memberId = md5(strtolower($email));
$dataCenter = substr($apiKey,strpos($apiKey,'-')+1);
$url = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/lists/' . $listId . '/members/' . $memberId;
$json = json_encode([
'email_address' => $email,
'status' => $status, // "subscribed","unsubscribed","cleaned","pending"
'merge_fields' => [
'FNAME' => $nome,
'LNAME' => $apelido,
'STATUSORI' => $status_ori,
]
]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $httpCode;
}
What could I be doing wrong?
I have a list button (php list plugin), to synchronize the list records, in the MailChimp list.
It is working, but only synchronizes the 1st selected record.
I have the following code:
$app = JFactory::getApplication();
$ids = $app->input->get('ids', array(), 'array');
foreach ($ids AS $myid)
{
$row = $model->getRow($myid);
$email = $row->tb_contactos_geral___email_login_ctg;
$nome = $row->tb_contactos_geral___nome_ctg;
$apelido = $row->tb_contactos_geral___apelido_ctg;
$status_ori = $row->tb_contactos_geral___status_ctg;
$status = "subscribed";
$apiKey = 'myapikey';
$listId = 'mylistid';
$memberId = md5(strtolower($email));
$dataCenter = substr($apiKey,strpos($apiKey,'-')+1);
$url = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/lists/' . $listId . '/members/' . $memberId;
$json = json_encode([
'email_address' => $email,
'status' => $status, // "subscribed","unsubscribed","cleaned","pending"
'merge_fields' => [
'FNAME' => $nome,
'LNAME' => $apelido,
'STATUSORI' => $status_ori,
]
]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $httpCode;
}
What could I be doing wrong?