Hello there,
I'm using PHP and the https://github.com/drewm/mailchimp-api/ API
When I'm doing this:
/**
* Allows one to test their segmentation rules before creating a campaign using them
* @param array $segment List segmentation parameters
* @return array Total users that match segment
*/
public function campaignsSegmentTest(array $segment)
{
$result = $this->mailChimp->call('campaigns/segment-test', array(
'list_id' => $this->mainListId,
'options' => array(
'match' => $segment['match'],
'conditions' => array(array(
'field' => $segment['field'],
'op' => $segment['operation'],
'value' => $segment['value'],
)),
),
));
return $result;
}
with parameters like : match: "any", (field: "Cities", op : 'like', value: '01012'), I'm getting the right amout of users and that suits me.
BUT
when I do a 'campaigns/create' without segment-opts it works, AND when I do it (exactly with the same parameters) with 'segment-opts' it fails.
$mailChimp->campaignsCreate('my_subject', 'my_template', '01012');
Which is in code:
/**
* Create a new draft campaign to send (you can not have more than 32,000 campaigns in your account)
* @param string $subject The subject of the mail
* @param string $template The template of the mail
* @param string $emailAddress (optional) Segment the main list with a single email address
* @param string $cityCode (optional) Segment the main list with a given city code
* @return array The whole information about the created campaign
*/
public function campaignsCreate($subject, $template, $emailAddress = null, $cityCode = null)
{
$campaignOptions = array(
'type' => 'regular',
'options' => array(
'list_id' => $this->mainListId,
'subject' => $subject,
'from_email' => 'my_...@mail.com',
'from_name' => 'Municipaly',
'to_name' => '',
//'title' => 'example title',
//'generate_text' => true,
),
'content' => array(
'html' => $template,
//'text' => 'example text',
),
);
/// this raises an error, to be fixed.
[...]
if ($cityCode) {
$campaignOptions['segment_opts'] = array(
'list_id' => $this->mainListId,
'options' => array(
'match' => 'any',
'conditions' => array(array(
'field' => 'Cities',
'op' => 'like',
'value' => sprintf('%%s%', $cityCode),
)),
),
);
}
$campaign = $this->mailChimp->call('campaigns/create', $campaignOptions);
if (isset($campaign['status']) && $campaign['status'] == 'error')
throw new \Exception(sprintf('[%s - %s] %s', $campaign['code'], $campaign['name'], $campaign['error']));
return $campaign['id'];
}
I get this error from your API : [506 - Invalid_Options] "match" must be "any" or "all"
and my Match is 'any'
Does someone see what I'm doing wrong and why I get this 506 error ?
Thank you,
Vincent
"segment_opts": {
"match": "any",
"conditions": [
{
"field": "Cities",
"op": "like",
"value": "10102"
}
]
}