This is an older topic but I want to share my solution based on @jimbobrjames’ kind help here (Uniform by @mzur + Mailchimp API - #4 by jimbobrjames) and in the discord channel. Maybe it helps someone in the future—especially since I can’t find any documentation on this from Mailchimp’s side.
Keeping Uniform’s validations in place but replacing the webhook action with a Remote
call wrapped in a try-catch-statement:
try {
$url = 'https://usXX.api.mailchimp.com/3.0/lists/XXXXXX/members/';
$data = [
'email_address' => $data['email'],
"status" => "pending",
'merge_fields' => [
'FNAME' => $data['firstname'],
'LNAME' => $data['lastname'],
],
];
$options = [
'headers' => [
'Content-Type: application/json',
'Authorization: Basic XXXXXX',
],
'method' => 'POST',
'data' => json_encode($data),
];
$response = Remote::request($url, $options);
// do whatever you need to with the response
} catch (Exception $error) {
return Response::json(['message' => 'The submission could not be sent: ' . $error->getMessage()], 400);
}