Issue when requesting create segments API v3 through PHP wrapper
Asked Answered
H

1

1

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)

enter image description here

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 -

enter image description here

How to override this problem?

Heim answered 4/1, 2017 at 13:45 Comment(3)
May you try to name the last array in your Method 1 based on your Segemnet Type, i.e. like this: "conditions"=>array("EmailAddress"=>array("op"=>"foo", ... )), check out the docs -> developer.mailchimp.com/documentation/mailchimp/reference/lists/….Sienese
@Andy: thanks, but it's didn't solve my problem.Heim
Ok, sorry. May you try to work round to achieve the expected result. Try to simply put a value into the array, then another array or an object, just every combination which comes in your mind and try to get content in the conditions-ArraySienese
Y
0

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

Yon answered 16/1, 2017 at 13:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.