Issue when requesting create segments API v3 through PHP wrapper

家住魔仙堡 提交于 2019-12-11 08:14:42

问题


I have test-driving for Mailchimp API v3 using your PHP wrapper. It's working great for me But when I'm creating a request using POST for "Create Segment" getting an error (attach screenshot):

Request Code is (through associative array) -

$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'))
        ));

This request call returning following error -

array (size=2) 'field' => string 'options.conditions' (length=18) 'message' => string 'Schema describes array, object found instead' (length=44)

I will also tried to create Request (through associative array) -

Method 1:

$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')))
        ));

Method 2:

$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')))
        ));

Both method will create segment on mailchimp account but not have any conditions. See screenshot -

How to override this problem?


回答1:


You are missing the condition_type param. It should be selected from the list provided by MailChimp in the endpoint documentation. For example, IF the field "type" from your MailChimp list is a text field you should use 'condition_type': 'TextMerge'. In this case, conditions should have the following format:

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

However, MailChimp MAY have a bug in this endpoint, since TextMerge works only on the EMAIL field. I have also stumbled upon this problem recently:

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

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



来源:https://stackoverflow.com/questions/41465345/issue-when-requesting-create-segments-api-v3-through-php-wrapper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!