I tried to refer to one of the answers in StackOverflow to create a new member in the list that I have. I am trying to use API v3.0. Below is a snippet of code.
$apikey = 'api_key_here'; $auth = base64_encode( 'user:'.$apikey ); $data = array( 'apikey' => $apikey, 'email_address' => '1111111@gmail.com', 'status' => 'subscribed', 'merge_fields' => array( 'FNAME' => 'Mihir' ) ); $json_data = json_encode($data); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://us2.api.mailchimp.com/3.0/lists/my_list_id_here/members/'); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Basic '.$auth)); curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data); $result = curl_exec($ch); var_dump($result); die('Mailchimp executed');
Here is the error message I get:
string(218) "{"type":"http://kb.mailchimp.com/api/error-docs/404-resource-not-found","title":"Resource Not Found","status":404,"detail":"The requested resource could not be found.","instance":"f03f3b5d-ef59-4452-b502-8a96449025df"}"
Help is much appreciated :)
Thanks, Mihir.
php curl mailchimp
Mihir chhatre
source share