Mailchimp cURL Add Member Error

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.

+8
php curl mailchimp
source share
3 answers

I assume that you did: went to the list, found the list to which you tried to add the participant, and took the ID parameter from the URL.

If so, you need to do the following: go to the admin page for the list to which you are trying to add a member. Click on the Settings drop-down menu. Scroll to "List Name and Defaults." Then use the identifier located in the "List of identifiers" section of this page.

+32
source share

Go to Lists> Settings> There you will see the list identifier:

enter image description here

+5
source share

This is probably because he cannot find the list. To check, try to get GET before /3.0/lists/your_list_id_here . If this returns 200, you want to talk to support, because everything else looks great. If you get 404, you will need to get the correct list id (which you can find when doing a GET on /lists/ ).

Also: your life will be made immeasurably easier without using cURL directly. I recommend Guzzle or PHP Requests

+1
source share

All Articles