UPDATE: Did not find a solution to the exact issue - the newer telnet class was also not connecting for me. I have, however, been able to get a perl connection using Net::Telnet component, then run a short php script to output ALL results. This happened within 3 seconds for 900+ results so all in all a good replacement.
Code now;
$operations = [];
foreach($users as $user) {
$operation = [
'method' => 'POST',
'path' => "/lists/$listId/members",
'operation_id' => $user['id'],
'body' => json_encode([
'email_address' => $user['email'],
'status' => $user['status'], // Create sync/button to allow BFCMA back end to change this with the DB to then update with daily/weekly batch request
//add additional fields to insert into MC
'merge_fields' => [ // 8/10/21 Stackoverflow suggests to use merge-fields *not currently working with it included
'FNAME' => $user['fname'],
'LNAME' => $user['lname']
]
])
];
array_push($operations, $operation);
}
// create object to put $operations array inside
$operationsObject = ['operations'=>$operations];
echo '<pre> ';
print_r($operationsObject);
echo '</pre>';
try {
$response = $mailchimp->batches->start($operationsObject);
// echo $response;
echo '<pre> ';
print_r($response);
echo '</pre>';
} catch (\MailchimpMarketing\ApiException $e) {
echo $e->getMessage();
}
In addition, here is the final part of the code if you were to include the json_encode;
// create object to put $operations array inside
$operationsObject = ['operations'=>$operations];
echo '<pre> ';
print_r($operationsObject);
echo '</pre>';
$json = json_encode($operationsObject, JSON_PRETTY_PRINT);
echo '<pre> ';
print_r($json);
echo '</pre>';
try {
$response = $mailchimp->batches->start($json);
// echo $response;
echo '<pre> ';
print_r($response);
echo '</pre>';
} catch (\MailchimpMarketing\ApiException $e) {
echo $e->getMessage();
}
Yes it was.
Found an answer that worked - I added JSON_UNESCAPED_SLASHES when encoding the data.
$body = json_encode($body_data, JSON_UNESCAPED_SLASHES);
Also unquoted the networkAdministrators array values and the call was successful.
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.