【问题标题】:Explain a MailChimp API error message: The resource 'Campaign_Collection' could not be found解释 MailChimp API 错误消息:找不到资源“Campaign_Collection”
【发布时间】:2017-04-20 12:45:09
【问题描述】:

我正在将我们升级到新的 MailChimp v3 API。

FWIW,我们使用的是DrewM's PHP library

当我尝试create a new campaign 时,我从 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] =>
)

URL (http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary) 只是部分有用;是的,缺少资源。但是什么是 Campaign_Collection?它是 Mailchimp 列表吗? Mailchimp 文件夹?我需要使用某种数组结构来指定某种形式的数据?

【问题讨论】:

  • StackOverflow 上的 MC 开发人员比坐在 Web 表单后面的支持人员更有可能回复得更快。

标签: php mailchimp mailchimp-api-v3.0


【解决方案1】:

问题解决了。

如果报错,404字段是关键线索,detail字段是红鲱鱼。

如果您拼错端点,就会出现这种错误。例如:

$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" => "",
   ]
>>>

我,我在 Campaigns 端点上留下了一个“s”。

【讨论】:

    【解决方案2】:
    $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;
    }
    

    必须在正文数据中包含合并字段...

    【讨论】:

    • 感谢您的回答,但不,这不是发生错误的原因。发生错误是因为我点击了$mail->get('campaign'); INSTEAD 的$mail->get('campaigns');(注意复数形式)。 MailChimp 的通用错误消息当时具有误导性。
    【解决方案3】:

    也许它太晚了,但认为它可能对其他人有所帮助。 通常 Mailchimp 会返回“找不到请求的资源。”而不告诉它是否是由于您的列表 ID 或方法等。

    确保您使用的是正确的列表 ID。它不是您在您的网址上看到的那个。从顶部菜单中,您需要转到 Audience 并选择“All Contacts

    那你该走了:

    Audience -> Settings -> Audience Name and defaults
    

    然后你会在右栏看到“Audience ID”,上面有一些奇怪的、毫无意义的解释:

    某些插件和集成可能会请求您的受众 ID。通常,这就是他们想要的:abcd1234xxx。

    这就是你需要的“listID”!

    PS:如果它被称为“AudienceID”,那么它应该在 API Ref 上更新。我相信文档为audienceID,而不是listID

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-21
      • 2021-12-11
      • 2017-05-21
      • 2014-12-15
      • 2016-09-11
      • 2016-07-10
      • 1970-01-01
      相关资源
      最近更新 更多