Option 'segment_ops' raising error 506 on 'campaigns/create'

217 views
Skip to first unread message

Vincent Le Jeune

unread,
Jan 21, 2014, 5:44:06 PM1/21/14
to mailchimp-...@googlegroups.com

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

Patrick

unread,
Jan 21, 2014, 5:59:22 PM1/21/14
to mailchimp-...@googlegroups.com
Vincent,

You're close, but your parameter format is not quite right.  segment_opts shouldn't have a list_id in it, remove that and move your "options" array up one level.  Here's what it should end up looking like:
"segment_opts": {
       
"match": "any",
       
"conditions": [
           
{
               
"field": "Cities",
               
"op": "like",
               
"value": "10102"
           
}
       
]
   
}


Patrick

Vincent Le Jeune

unread,
Jan 21, 2014, 6:43:41 PM1/21/14
to mailchimp-...@googlegroups.com
Thanks Patrick for your quick and efficient response, it works great. Sometimes I guess I don't get the APIs functions completely ;)
Later!
Reply all
Reply to author
Forward
0 new messages