SegmentOpts saved are different than SegmentOpts read.

56 views
Skip to first unread message

Will

unread,
Jun 5, 2010, 10:36:11 PM6/5/10
to MailChimp API Discuss
Hello,

My application creates segments on-the-efly... And before committing
them, the user must validate them (technically, to make a call to
SegmentTest). If the Segments pass the validation, the user is given
the option to save them to the campaign.

So far, the program is working great. It returns the correct number of
members for the segment... and after saving the segment to MailChimp,
I verified it by the WebApp and the segment and the member count
matches exactly... So I guess everything is OK in this.

However, in the "Campaigns List" of my app... I gave the user the
option to know if a given campaign has a segment defined... or if it
will be sent the whole list.

The problem is that in the loop where I cycle on the campaigns, I'm
getting a different Segments Group than the one I saved in the first
process and, even worst, the one it is returning does not even work.
It returns: This list does not contain the Merge Field
“timestamp_opt” (when I NEVER included that field in my original
segment opts).

For intance, here are two dumps of the Segment Opts: Before saving
(which based on the MailChimp WebApp is working fine) and one read in
the loop of the campaigns:

From the "saving" process":
Campaign ID: 2bb79ccc94 (List ID: 56652532b8)
Array
(
[match] => any
[conditions] => Array
(
[0] => Array
(
[field] => date
[op] => gt
[value] => 127c6c9b1a
)

)

)

From the "looping" process:
( technically: $retval = $api-
>campaignSegmentTest($campaign['list_id'],
$campaign['segment_opts']); )

Campaign ID: 2bb79ccc94 (List ID: 56652532b8)
Array
(
[match] => any
[conditions] => Array
(
[0] => Array
(
[field] => timestamp_opt
[op] => gt
[value] => campaign
[extra] => 1077329
)

)

)


Why does it change my Segment Opts? How do I solve it?

Thanks in advance,
Will

jesse

unread,
Jun 7, 2010, 3:39:21 PM6/7/10
to MailChimp API Discuss
We don't store them internally the same way that they are passed in
via the API. The mappings for date field segments has been fixed.


jesse

Will

unread,
Jun 7, 2010, 3:49:58 PM6/7/10
to MailChimp API Discuss
Thank you! I works great now.

Will

unread,
Jun 7, 2010, 3:51:45 PM6/7/10
to MailChimp API Discuss


On Jun 7, 3:49 pm, Will <edu...@gmail.com> wrote:
> Thank you! I works great now.

Well... "I" don't work that great... But IT certainly does.

Thank you...

Will

unread,
Jun 7, 2010, 4:08:01 PM6/7/10
to MailChimp API Discuss
I spoke too soon.

It is an expected behaviour that after any campaign update (say,
updating the subject), the Segment get deleted?

I.e.-

1.- A define a segmentation on a draft, regular campaign
2.- I double check the segments in the campaign and they are as
expected.
3.- Then, I decide to change its subject so I did it.
4.- After the update, the segments are deleted so if it is send right
away, it gets send to the whole list.

Is it as it should work? Or it is deleting the segment by mistake?

Will

unread,
Jun 7, 2010, 4:18:32 PM6/7/10
to MailChimp API Discuss
I?m solving the problem by reading the segments at the beggining of
the process... and updating them at the end of it... but it's not
correct.

jesse

unread,
Jun 7, 2010, 4:28:43 PM6/7/10
to MailChimp API Discuss
I can't replicate that - you should double check the actual process
your code is going through and I imagine you'll find somewhere where
you are overwriting it with a blank value using another campaignUpdate
call.


jesse

On Jun 7, 4:08 pm, Will <edu...@gmail.com> wrote:

Will

unread,
Jun 7, 2010, 4:52:16 PM6/7/10
to MailChimp API Discuss
Ok. The place were I set the Segments (and where I schedule campaigns
too by the way) are totally different than the place where I modified
the common fields of the campaign such as from_name, from_email,
subject, etc.

Just to be sure, I search my whole code looking for segment_opts and
campaign_update... and the logic is pretty simple.

I'm affraid the problem is not in my end.

In fact... See very solution I gave it, tells me that the problem is
in Mailchimp servers. Here's the code (with my "solution" with
asterisks prefixed. There were not there initially):

As you can see, there's no way to update segment_opts with a blank
field.
$options = array(
'list_id' => $lid,
'subject' => $subject,
'from_email' => $from_email,
'from_name' => $from_name,
'to_email' => '$to_email,
'tracking' => array(
'opens' => ($track_opens?true:false),
'html_clicks' => ($track_clicks?true:false),
'text_clicks' => ($track_texto?true:false)
),
'title' => $title,
'authenticate' => ($authenticate?true:false),
'auto_footer' => false,
'inline_css' => false,
'generate_text' => false

);
if ( $cid != 0) {
*** $c = tcm_get_campaign($cid);

$error_lines = '';
foreach ($options as $key => $option) {
if ( !$api->campaignUpdate( $cid, $key,$option ) ) {
if ( $error_lines != '' ) {
$error_lines .= ', ';
}
$error_lines .= $api->errorMessage;
}
}
if ( !$api->campaignUpdate( $cid, 'content', $content ) ) {
if ( $error_lines != '' ) {
$error_lines .= ', ';
}
$error_lines .= $api->errorMessage;
}
*** $api->campaignUpdate( $cid, 'segment_opts',
$c['segment_opts'] );
} else { // creating a new campaign



All best,
Will

jesse

unread,
Jun 7, 2010, 5:14:14 PM6/7/10
to MailChimp API Discuss
Simplify your code when testing something like this - make a simple
call to campaignUpdate to change the subject and see if the segment
disappears (it won't).

From you code, my first guess would be that your tcm_get_campaign()
function is returning the result from campaigns() - if that's the
case, $c['segment_opts'] won't be set because the return is any array,
so you'd need to use $c[0]['segment_opts'] or fix the function to
return the single array element.


jesse

Will

unread,
Jun 7, 2010, 5:19:39 PM6/7/10
to MailChimp API Discuss
tcm_get_campaign() returns the first first element of the array
returned by campaigns(array('campaign_id' => $cid) so that's not the
case.

And that couple lines with *** prefixed were added after I noticed the
error and they solve the problem (not cause them)(... at the cost of
two API calls I found unecessary.

If I remove those couple lines, the segment dissapears with no
apparent reason, given the remaining code :(
Reply all
Reply to author
Forward
0 new messages