Mailchimp错误:错误的请求-您的广告系列尚未准备好发送 [英] Mailchimp Error: Bad Request - Your Campaign is not ready to send

查看:185
本文介绍了Mailchimp错误:错误的请求-您的广告系列尚未准备好发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下教程来创建广告系列,并使用Php在MailChimp中发送电子邮件.

I am using following tutorial to create campaign and send email in MailChimp using Php.

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等,但仍然出现错误

I have updated all values, including API KEY, List ID, template ID etc. but still i am getting errors

这是错误对象

stdClass Object ( [type] => http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/ [title] => Bad Request [status] => 400 [detail] => Your Campaign is not ready to send. [instance] => 89dc8734-2611-4f3b-a4f7-d18bd181bded )

stdClass Object ( [type] => http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/ [title] => Bad Request [status] => 400 [detail] => Your Campaign is not ready to send. [instance] => 89dc8734-2611-4f3b-a4f7-d18bd181bded )

我检查了Mail Chimp,在其中创建了广告系列,但将其另存为草稿.

I checked in Mail Chimp, campaigns are created there but they are saved as Draft.

这是我的API日志

API日志 https://drive.google.com/file/d/0BwIWuJmCDI1vNHgtVm9TQm1FM view?usp = drivesdk

我能够创建广告系列,为广告系列设置模板,但是我无法发送电子邮件.我的域也已根据指南通过Mailchimp进行了验证和身份验证. 请检查并提出解决方案

I am able to create campaign, set a template to campaign but i cannot send emails. My Domain is also verified and authenticated with Mailchimp using guidelines. Please check and suggest a solution

推荐答案

虽然您的广告系列尚未准备好发送"消息不是很有帮助,但是您可以在MailChimp本身中查看更详细的消息.编辑API创建的草稿,然后导航到最后的确认"步骤.您会看到一个检查表,其中大多数项目都通过了检查,但还会有一个项目解释该广告系列失败的原因.

While the "Your Campaign is not ready to send" message isn't very helpful, you can check for a more detailed message in MailChimp itself. Edit the draft that the API created, and navigate to the final Confirm step. You'll see a checklist where most of the items passed, but there will also be an item that explains why the campaign failed.

当我尝试复制问题时,由于模板中保留了一些默认占位符文本,因此广告系列无法发送.由于您发布的代码仅将内容设置为一个块,因此这可能与您遇到的问题相同.

When I attempted to replicate the issue, the campaign failed to send because there was some default placeholder text left unchanged in the template. Since the code you posted only sets the content for one block, this is probably the same issue you're having.

希望这会有所帮助!

这篇关于Mailchimp错误:错误的请求-您的广告系列尚未准备好发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆