dimanche 19 avril 2015

mailchimp http error: you must specify a apikey

I'm the using MailChimp 2.0 api and trying to post a lists/subscribe call using php. The call is returning an error "You must specify a apikey value".


Here's the code that makes the post:



function json_post ($url, $params)
{
print '<p>url = ' . $url . '</p>';
$data = json_encode ($params);
print '<p>data = ' . $data . '</p>';

$handle = curl_init ($url);
curl_setopt ($handle, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt ($handle, CURLOPT_POST_FIELDS, $data);
curl_setopt ($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($handle, CURLOPT_HTTPHEADER, array ('Content-Type: application/json',
'Content-Length: ' . strlen($data_string)));

$result = curl_exec ($handle);
print '<p>curl_error: ' . curl_errno ($handle) . '</p>';
return $result;
}


The print statements show:



url = http://ift.tt/1ytN3Tn

data = {"apikey":"...","id":"...","email":{"email":"test1@abc.com"},"merge_vars":{"groupings":{"name":"test"}}}

curl_error: 0

{"status":"error","code":-100,"name":"ValidationError","error":"You must specify a apikey value"}


I presume there's something wrong with the syntax. The api key is cut & pasted from my mailchimp account page. I've tried it with and without the -us10 suffix. Any ideas?


Aucun commentaire:

Enregistrer un commentaire