Problem requesting to create API v3 segments using PHP wrapper

I have a test drive for Mailchimp API v3 using your PHP shell. It works great for me. But when I create a request using POST to create a "Create Segment", you will get an error message (attach a screenshot):

Request code (through an 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 call request returns the following error -

array (size = 2) 'field' => string 'options.conditions' (length = 18) 'message' => string 'The scheme describes the array, the found object instead of' (Length = 44)

enter image description here

I will also try to create a Request (via an 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 methods will create a segment on the mailchimp account, but will not have any conditions. See screenshot -

enter image description here

How to fix this problem?

+1
source share
1 answer

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

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

However, MailChimp MAY have an error at this endpoint, because TextMerge only works in the EMAIL field. I recently came across this problem:

Mailchimp api v3 - cannot create a segment based on the TEXT merge field

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

0
source

Source: https://habr.com/ru/post/1232550/


All Articles