Mailchimp API 2.0 使用组订阅用户 - 复选框值

Mailchimp API 2.0 Subscribing users with groups - checkbox value

我对如何使用 API 2.0 在 Mailchimp 表单中检索和发送我的复选框的值感到困惑。 在我的表格末尾,我有这个复选框

 <input type="checkbox" checked data-dojo-type="dijit/form/CheckBox" id="group_1" name="group[4909][1]" value="1"  class="av-checkbox"><span id="message-check">YES, I agree to be contacted by ... for promotions and special offers.</span>

这里是我的 php 代码,用于通过 API 连接和发送数据:

$email = array('email' => htmlentities($_REQUEST['MERGE0']));
$merge_vars = array(
'MMERGE3' => $_REQUEST['MERGE3'], //Voucher value
'MMERGE4' => $_REQUEST['MERGE4'], //Date value
'MMERGE6' => $_REQUEST['MERGE6'],  //Sales Person value
'FNAME' => $_REQUEST['MERGE1'],   //First Name value
'LNAME' => $_REQUEST['MERGE2'],   //Last Name value
'MMERGE5' => $_REQUEST['MERGE5'], //Phone value
'groupings' => array(
    'id' => '4909',
    'name' => "Offers",
    'groups' => $_REQUEST['group']
    )
);
require('Mailchimp.php');
$Mailchimp = new Mailchimp( $api_key );
$Mailchimp_Lists = new Mailchimp_Lists( $Mailchimp );
$subscriber = $Mailchimp_Lists->subscribe($list_id, $email,  $merge_vars, $email_type, $double_optin);

我遵循了这个文档https://apidocs.mailchimp.com/api/2.0/lists/subscribe.php

所有字段凭证、日期、销售额、名字和姓氏以及 Phone 都已发送,用户已在我的列表中订阅。我唯一缺少的值是复选框。我想至少发送 "Yes" 或“1”到我的复选框列表。 想不通!

大家有什么建议吗?

谢谢。 文斯.

好的,在发布我的问题 1 小时后,我找到了解决方案。

这里是适合我的正确代码:

$merge_vars = array(
'MMERGE3' => $_REQUEST['MERGE3'], //Voucher value
'MMERGE4' => $_REQUEST['MERGE4'], //Date value
'MMERGE6' => $_REQUEST['MERGE6'],  //Sales Person value
'FNAME' => $_REQUEST['MERGE1'],   //First Name value
'LNAME' => $_REQUEST['MERGE2'],   //Last Name value
'MMERGE5' => $_REQUEST['MERGE5'], //Phone value
'GROUPINGS' => array(
    0 => array(
        'id' => '4909', // need grouping ID
        'groups' => array( 'YES, I agree to be contacted by ... for promotions and special offers.' )
    )
),
);

换句话说,我打印出了列表中的组 ID:

//Print the current group of a list
/*$current_groupings = $Mailchimp->call( 'lists/interest-groupings', array(
            'id' => 'your_list_ID',
        ) );
var_dump($current_groupings);*/

我得到了组的整个数组:

array(1) { 
[0]=> array(5) {
    ["id"]=> int(4909) 
    ["name"]=> string(6) "Offers" 
    ["form_field"]=> string(10) "checkboxes" 
    ["display_order"]=> string(1) "0" 
    ["groups"]=> array(1) { 
        [0]=> array(5) { 
            ["id"]=> int(17445) 
            ["bit"]=> string(1) "1" 
            ["name"]=> string(89) "YES, I agree to be contacted by ... for promotions and special offers." 
            ["display_order"]=> string(1) "1" 
            ["subscribers"]=> NULL 
        } 
    } 
} 
}

所以很容易理解我需要使用:

  1. 本例中的组 ID 4909
  2. 以及在这种情况下的组名称:"YES, I agree to be contacted by ... for promotions and special offers."

就是这样。作品! 希望这对其他人有帮助。

干杯, 文斯.