Paddy Hallihan
Paddy Hallihan

Reputation: 1686

Errors using MailChimp API adding email address to list

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);

?>

Upvotes: 1

Views: 1799

Answers (3)

ahong
ahong

Reputation: 1250

It was a transient error for me, which went away after a couple of minutes. If it doesn't then somehow Akamai has probably blacklisted you and you need to contact Mailchimp (as Akamai does not handle Mailchimp specific requests directly).

If you look in the response headers, it says Server: AkamaiGHost, which I assume is the proxy Mailchimp is using. Also the response is text/html, which does not match Mailchimp's own documented error formats–another sign that it is the proxy blocking you and not Mailchimp itself.

Upvotes: 0

Jose
Jose

Reputation: 322

I think the IP of your server is blacklisted for Mailchimp. You should contact Mailchimp and ask if the server IP is blacklisted for them.

Upvotes: 0

Boris
Boris

Reputation: 306

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/

Upvotes: 2

Related Questions