I am trying to add email addresses to my mailchimp mailing list but am getting an error saying
Access Denied You don't have permission to access "http://us9.api.mailchimp.com/3.0/lists/######/members/" on this server. Reference #18.1e89655f.1546511382.213522b5
I have just created the API key and haven’t done much with MailChimp before. I think the list ID is correct, I just grabbed it from the URL of my actual list in a browser https://us9.admin.mailchimp.com/lists/members/?id=######
<?php $email = '####@####.##'; $authToken = '#######################-us9'; $email_list = '######'; $postData = array( "email_address" => "$email", "status" => "subscribed", "merge_fields" => array( "NAME"=> "", "PHONE"=> "") ); $ch = curl_init('https://us9.api.mailchimp.com/3.0/lists/'.$email_list.'/members/'); curl_setopt_array($ch, array( CURLOPT_POST => TRUE, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_HTTPHEADER => array( 'Authorization: apikey '.$authToken, 'Content-Type: application/json' ), CURLOPT_POSTFIELDS => json_encode($postData) )); $response = curl_exec($ch); var_dump($response); ?>
Advertisement
Answer
The API list ID is not the same as the browser one. (Don’t ask me why). To find out the API list ID, use the API Playground. https://developer.mailchimp.com/