gpt4 book ai didi

php - Mailchimp 错误 : Bad Request - Your Campaign is not ready to send

转载 作者:搜寻专家 更新时间:2023-10-31 20:59:38 30 4
gpt4 key购买 nike

我正在使用以下教程使用 Php 在 MailChimp 中创建事件和发送电子邮件。

https://isabelcastillo.com/create-send-mailchimp-campaign-api-3

我的代码是

    require_once('../wp-load.php');

function isa_mailchimp_api_request( $endpoint, $type = 'POST', $body = '' )
{
// Configure --------------------------------------
$api_key = 'API KEY HERE'; // Changed API Key here
// STOP Configuring -------------------------------
$core_api_endpoint = 'https://<dc>.api.mailchimp.com/3.0/';
list(, $datacenter) = explode( '-', $api_key );
$core_api_endpoint = str_replace( '<dc>', $datacenter, $core_api_endpoint );

$url = $core_api_endpoint . $endpoint;
//print_r($url );

$request_args = array(
'method' => $type,
'timeout' => 20,
'headers' => array(
'Content-Type' => 'application/json',
'Authorization' => 'apikey ' . $api_key
)
);

if ( $body ) {
$request_args['body'] = json_encode( $body );
}

$request = wp_remote_post( $url, $request_args );
$response = is_wp_error( $request ) ? false : json_decode( wp_remote_retrieve_body( $request ) );


echo '<pre>';
print_r($response);

return $response;
}



function isa_create_mailchimp_campaign( $list_id, $subject ) {
$reply_to = 'info@newslume.com';
$from_name = 'NewsLume';
$subject= 'Another new test message 14 17';
$campaign_id = '';
$body = array(
'recipients' => array('list_id' => $list_id),
'type' => 'regular',
'settings' => array('subject_line' => $subject,
'title' => 'a test title NewsLUme',
'reply_to' => $reply_to,
'from_name' => $from_name,
'use_conversation'=> false,
'to_name'=> 'sajid',

'auto_footer'=> false,
'inline_css'=> false,
'auto_tweet'=> false,
'drag_and_drop'=> false

)
);

$create_campaign = isa_mailchimp_api_request( 'campaigns', 'POST', $body );

if ( $create_campaign ) {
if ( ! empty( $create_campaign->id ) && isset( $create_campaign->status ) && 'save' == $create_campaign->status ) {
// The campaign id:
$campaign_id = $create_campaign->id;
}
}

return $campaign_id ? $campaign_id : false;

}

function isa_set_mail_campaign_content( $campaign_id, $template_content ) {
$set_content = '';
$set_campaign_content = isa_mailchimp_api_request( "campaigns/$campaign_id/content", 'PUT', $template_content );

if ( $set_campaign_content ) {
if ( ! empty( $set_campaign_content->html ) ) {
$set_content = true;
}
}
return $set_content ? true : false;
}


$list_id='my_list_id_here'; // LIST HERE

$campaign_id = isa_create_mailchimp_campaign( $list_id, $subject );

if ( $campaign_id ) {
// Set the content for this campaign
$template_content = array(
'template' => array(
// The id of the template to use.
'id' => 47615, // INTEGER
'sections' => array(
'tst_content' => 'THIS IS THE CONTENT BODY OF MY EMAIL MESSAGE.'
)

)
);
$set_campaign_content = isa_set_mail_campaign_content( $campaign_id, $template_content );


if ( $set_campaign_content ) {

$send_campaign = isa_mailchimp_api_request( "campaigns/$campaign_id/actions/send", 'POST' );
if ( empty( $send_campaign ) ) {
// Campaign was sent!
} elseif( isset( $send_campaign->detail ) ) {
$error_detail = $send_campaign->detail;

}

}

}

我已经更新了所有值,包括 API KEY、列表 ID、模板 ID 等,但我仍然收到错误

这是错误对象

stdClass 对象
(
[类型] => http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/
[标题] => 错误请求
[状态] => 400
[详细信息] => 您的营销事件尚未准备好发送。
[实例] => 89dc8734-2611-4f3b-a4f7-d18bd181bded
)

我检查了 Mail Chimp,在那里创建了事件,但它们保存为草稿。

这是我的 API 日志

API 日志可以通过点击下面的链接查看 https://drive.google.com/file/d/0BwIWuJmCDI1vNHgtVm9TQm1FMVU/view?usp=drivesdk

我可以创建事件,为事件设置模板,但我无法发送电子邮件。 My Domain 也使用指南通过 Mailchimp 进行了验证和认证。请检查并提出解决方案

最佳答案

虽然“您的营销事件尚未准备好发送”消息不是很有帮助,但您可以在 MailChimp 本身中查看更详细的消息。编辑 API 创建的草稿,然后导航到最后的确认步骤。您会看到一个 list ,其中大部分项目都通过了检查,但也会有一个项目解释了事件失败的原因。

当我尝试重现该问题时,事件发送失败,因为模板中有一些默认占位符文本未更改。由于您发布的代码只设置了一个 block 的内容,这可能与您遇到的问题相同。

希望这对您有所帮助!

关于php - Mailchimp 错误 : Bad Request - Your Campaign is not ready to send,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46238251/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com