Php 解释MailChimp API错误消息:找不到资源“Campaign_Collection”

Php 解释MailChimp API错误消息:找不到资源“Campaign_Collection”,php,mailchimp,mailchimp-api-v3.0,Php,Mailchimp,Mailchimp Api V3.0,我正在升级到新的MailChimp v3 API FWIW,我们正在使用 当我尝试这样做时,我从MailChimp收到一条神秘的错误消息: Array ( [type] => http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/ [title] => Resource Not Found [status] => 404 [detail] => The re

我正在升级到新的MailChimp v3 API

FWIW,我们正在使用

当我尝试这样做时,我从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只是部分有用;是,缺少一个资源。但什么是竞选活动?这是邮件列表吗?邮件夹?我需要使用某种数组构造来指定某种形式的数据?

问题已解决

如果您得到了错误,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" => "",
   ]
>>>
在我看来,我在活动结束点上留下了一个“s”。

问题解决了

$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;
}
如果您得到了错误,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" => "",
   ]
>>>
对我来说,我在竞选活动的终点上留下了一个“s”

$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;
}
必须包含已归档到正文数据中的合并字段


必须包括将字段合并到身体数据中…

可能太晚了,但认为这可能对其他人有帮助。 通常,Mailchimp返回找不到请求的资源。不告诉是否是由于您的列表id或方法等

确保您使用的列表id正确。它不是您在URL上看到的列表id。从顶部菜单中,您需要转到观众并选择所有联系人

那么你需要去:

Audience -> Settings -> Audience Name and defaults
然后在右边的专栏中,你会看到观众ID,其中有一些奇怪的、毫无意义的解释,如:

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

这就是你需要的列表ID


PS:如果它被称为AudenceId,那么它应该在API参考文档中更新为AudenceId,而不是我认为的listID。

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

确保您使用的列表id正确。它不是您在URL上看到的列表id。从顶部菜单中,您需要转到观众并选择所有联系人

那么你需要去:

Audience -> Settings -> Audience Name and defaults
然后在右边的专栏中,你会看到观众ID,其中有一些奇怪的、毫无意义的解释,如:

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

这就是你需要的列表ID


PS:如果它被称为AudenceId,那么它应该在API参考文档中更新为AudenceId,我相信不是listID。

StackOverflow上的MC开发人员比该web表单后面的支持人员回复得更快。StackOverflow上的MC开发人员比该web表单后面的支持人员回复得更快。谢谢您的回答,但不,这不是发生错误的原因。发生错误是因为我点击了$mail->get'campaign';而不是$mail->get'campaigns';请注意多元化。MailChimp的一般错误信息在当时是误导性的。谢谢你的回答,但不,这不是错误发生的原因。发生错误是因为我点击了$mail->get'campaign';而不是$mail->get'campaigns';请注意多元化。MailChimp的一般错误信息在当时具有误导性。