【问题标题】:Issue when requesting create segments API v3 through PHP wrapper通过 PHP 包装器请求创建分段 API v3 时的问题
【发布时间】:2017-05-18 20:01:07
【问题描述】:

我使用您的 PHP 包装器测试了 Mailchimp API v3。它对我很有用但是当我使用 POST 为“创建段”创建请求时出现错误(附上截图):

请求代码是(通过关联数组)-

$api_key = "xxxxxxxxxxxxxxxx-us11";
$list_id = "1xx2xx3xx4xx";
$MailChimp = new MailChimp($api_key);
$result = $MailChimp->post('lists/' . $list_id . '/segments', array('name' => 'Testing Data',
    'options' => array('match' => 'all',
        'conditions' => array('field' => 'type', 'op' => 'is', 'value' => 'Testing'))
        ));

此请求调用返回以下错误 -

array (size=2) 'field' => string 'options.conditions' (length=18) 'message' => string 'Schema 描述了数组,而是找到了对象' (长度=44)

我也会尝试创建请求(通过关联数组)-

方法一:

$api_key = "xxxxxxxxxxxxxxxx-us11";
$list_id = "1xx2xx3xx4xx";
$MailChimp = new MailChimp($api_key);
$result = $MailChimp->post('lists/' . $list_id . '/segments', array('name' => 'Testing Data',
    'options' => array('match' => 'all',
        'conditions' => array(array('field' => 'type', 'op' => 'is', 'value' => 'Testing')))
        ));

方法二:

$api_key = "xxxxxxxxxxxxxxxx-us11";
$list_id = "1xx2xx3xx4xx";
$MailChimp = new MailChimp($api_key);
$result = $MailChimp->post('lists/' . $list_id . '/segments', array('name' => 'Testing Data 4',
    'options' => array('match' => 'all',
        'conditions' => array(array('field' => 'type'), array('op' => 'is'), array('value' => 'Testing')))
        ));

这两种方法都会在 mailchimp 帐户上创建段,但没有任何条件。看截图 -

如何解决这个问题?

【问题讨论】:

  • 您可以尝试根据您的 Segemnet 类型命名您的 方法 1 中的最后一个数组,例如:"conditions"=>array("EmailAddress"=>array("op"=>"foo", ... )),查看文档 -> developer.mailchimp.com/documentation/mailchimp/reference/lists/… .
  • @Andy:谢谢,但这并没有解决我的问题。
  • 好的,抱歉。愿你努力工作以达到预期的结果。尝试简单地将一个值放入数组,然后是另一个数组或对象,只是你想到的每个组合,并尝试在conditions-Array 中获取内容

标签: php mailchimp-api-v3.0


【解决方案1】:

您缺少 condition_type 参数。它应该从端点文档中 MailChimp 提供的列表中选择。 例如,如果 MailChimp 列表中的“类型”字段是文本字段,则应使用 'condition_type': 'TextMerge'。在这种情况下,条件应具有以下格式:

[
    {
        'condition_type': 'TextMerge',
        'field': 'type',
        'op': 'is',
        'value': 'Testing'
    }
]

但是,MailChimp 可能在此端点中存在错误,因为 TextMerge 仅适用于 EMAIL 字段。我最近也偶然发现了这个问题:

Mailchimp api v3 - can't create segment based on a TEXT merge field

https://github.com/drewm/mailchimp-api/issues/160

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-27
    • 2014-04-18
    • 1970-01-01
    • 1970-01-01
    • 2014-02-27
    • 2015-04-01
    • 2018-06-11
    • 2020-03-28
    相关资源
    最近更新 更多