0

I'm upgrading us to the new MailChimp v3 API.

FWIW, we're using DrewM's PHP library.

When I try to create a new campaign, I get this cryptic error message from MailChimp:

Array (
  [type] => http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/
  [title] => Resource Not Found
  [status] => 404
  [detail] => The resource 'Campaign_Collection' could not be found.
  [instance] =>
)

The URL (http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary) is only partially helpful; yes a resource is missing. But what is a Campaign_Collection? Is it a Mailchimp list? A Mailchimp folder? Some sort of array-construct I need to use to specify some form of data?

haz
  • 1,549
  • 15
  • 20

3 Answers3

6

Maybe it is too lat but thought it could be helpful to some other folks. Usually Mailchimp returns "The requested resource could not be found." without telling if it is due to your list id or method etc..

Make sure you are using the correct list id. It is NOT the one you see on your URL. From the top menu, you need to go to Audience and select "All Contacts"

enter image description here

Then you need to go:

Audience -> Settings -> Audience Name and defaults

enter image description here

Then on the right column you will see "Audience ID" with a some weird, meaningless explanation as:

"Some plugins and integrations may request your Audience ID. Typically, this is what they want: abcd1234xxx."

That is the "listID" you need!

enter image description here

PS: If it is called as "AudienceID" then it should be updated on the API Ref. Doc as audienceID, not listID I believe.

curiousBoy
  • 6,334
  • 5
  • 48
  • 56
2

Problem solved.

If you get the error, the 404 field is the key clue, and the detail field is a red herring.

This is the sort of error you get if you misspell an endpoint. For example:

$mailer = new MailChimp('****YOUR API KEY****');
$response = $mailer->get('/xyzzy');

// Produces this:
$response = [
     "type" => "http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/",
     "title" => "Resource Not Found",
     "status" => 404,
     "detail" => "The resource 'Xyzzy_Collection' could not be found.",
     "instance" => "",
   ]
>>>

Me, I had left off an 's' off the Campaigns endpoint.

haz
  • 1,549
  • 15
  • 20
-1
$data = [
        'email_address' => (isset($email) ? $email : ''),
        'status' => 'subscribed',
        'status_if_new' => 'subscribed',
        'merge_fields' => [
            'FNAME' => (isset($firstname) ? $firstname : ''),
            'LNAME' => (isset($lastname) ? $lastname : ''),
            'PHONE' => (isset($phone) ? $phone : ''),
        ],
    ];
    $server = explode('-', $token);
    $url = 'https://'.$server[1].'.api.mailchimp.com/3.0/lists/'.$list.'/members/';

$response = wp_remote_post( $url, [
    'method' => 'POST',
    'data_format' => 'body',
    'timeout' => 45,
    'headers' => [

                    'Authorization' => 'apikey '.$token,
                    'Content-Type' => 'application/json; charset=utf-8'
            ],
    'body' => json_encode($data )
    ]
);
if ( is_wp_error( $response ) ) {
   $error_message = $response->get_error_message();
    $return['error'] = "Something went wrong: $error_message";
} else {
    $return['success'] = $response;
}

Must be include merge_fields filed into body data...

  • Thanks for your answer, but no, that's not why the error was occurring. The error occurred because I had hit `$mail->get('campaign');` INSTEAD of `$mail->get('campaigns');` (note the pluralisation). MailChimp's generic error message was misleading at the time. – haz Oct 03 '19 at 05:44