Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mailchimp cURL "Add Member" Error

I tried referring to one of the answers on StackOverflow to create a new member in a list that I currently own. I am trying to use API v3.0. Below is the code excerpt.

        $apikey = 'api_key_here';
        $auth = base64_encode( 'user:'.$apikey );

        $data = array(
            'apikey'        => $apikey,
            'email_address' => '[email protected]',
            '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 reply I am receiving:

        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.

like image 776
Mihir Chhatre Avatar asked Jul 01 '15 15:07

Mihir Chhatre


2 Answers

What I'm assuming you did: Navigated to Lists, found the list you were trying to add a member to, and took the ID get parameter out of the URL.

If that is the case, what you need to do is: Go to the admin page for the list you are trying to add a member to. Click on the Settings dropdown menu. Go to "List name and defaults". Then use the ID located in the "List ID" section of that page.

like image 157
Jonny Cook Avatar answered Oct 25 '22 00:10

Jonny Cook


Navigate to Lists > Settings > There you will see a List ID:

enter image description here

like image 34
Shawn Vader Avatar answered Oct 25 '22 00:10

Shawn Vader