Using an interest group segment to create a campaign in the PHP API

1,080 views
Skip to first unread message

dorfri

unread,
Aug 10, 2012, 4:39:01 AM8/10/12
to mailchimp-...@googlegroups.com
Hi

My list contains a group named "Notification" with 3 entries (let's say "notif1", "notif2" & "notif3").
When creating a campaign in the website UI, I am able to select a segmentation according to this group - for example, send only to users with "Group: Notification" is "one of" "notif1".
However, I can't seem to understand how to do this in the PHP API. I found the following code to create the $seg array to pass to the campaignCreate() method:
$seg['match'] = 'any';
$seg['conditions'][] = array('field'=>'fname', 'op'=>'like', 'value'=>'bob');

I tried to change the second row to something like:
$seg['conditions'][] = array('field'=>'notification', 'op'=>'one of', 'value'=>'Notif1');
With not luck... I tried a bunch of other stuff too (i.e. 'field'=>"group: notification") and no luck.

I really need it... does anyone know by chance how to do that? I guess it must be possible because it is possible to do that in the site's UI.

Thanks a lot!!!

jesse

unread,
Aug 10, 2012, 6:31:25 AM8/10/12
to mailchimp-...@googlegroups.com
The campaignCreate method you are attempting to use documents the segment_opts parameter:
http://apidocs.mailchimp.com/api/rtfm/campaigncreate.func.php

which points you to thorough documentation on how to configure/test that:

http://apidocs.mailchimp.com/api/rtfm/campaignsegmenttest.func.php

You can also read out an existing campaign using campaigns() to see how it is setup.


jesse

firfin

unread,
Jan 29, 2013, 4:12:02 PM1/29/13
to mailchimp-...@googlegroups.com
Sorry to disagree with you Jesse. But In general I find the documentation for the mailchimp api examplary. But this is not the case for using interest groups. It could really use an example. Docs state:

Field = "interests-X": where X is the Grouping Id from listInterestGroupings()
Valid Op(erations): one / none / all
Valid Values: a comma delimited of interest groups for the list - see listInterestGroupings()

The first two keys are not that hard. They are more or less the same as most other conditions. Basically the same as the example at the bottom. However this 'values' key seems to be the only one that can take multiple values. As such, I think it deserves some extra attention.

The explanation is not clear either. I think there are some words missing in that explanation? An exact example would be much appreciated. Also, what is meant by 'interest groups' :
- The values of the struct['groups']['name'] ?
- The  array index of the group in the struct returned by listInterestGroupings ?
- in an array?
- should this array be keyed then?
- can it also be a single value? or does this always need to be wrapped in an array?


Questions abound. I think you will have to agree this isn't the best part of the api.

Kind regards

jesse

unread,
Jan 30, 2013, 5:40:40 AM1/30/13
to mailchimp-...@googlegroups.com
listInterestGroupings says it returns "list of interest groups for the list" - those have names and from setting them with, say, listSubscribe, one should generally be used to working with them. So yes to your first option. Nothing says anything about an array, so I have no idea why that was brought up.


jesse

firfin

unread,
Jan 30, 2013, 6:50:17 AM1/30/13
to mailchimp-...@googlegroups.com
The documentation states valid values : a comma delimited of interest groups for the list
A comma delimited what? I assumed a list. An array would make sense to me as that is the default type for a list in php. That is why I brought arrays up.

But if I understand correctly a valid value is simply a string with the 'names' of the groups seperated by ,  ?
Like this 'nameA, name3, nameX' ?




P.S.
And I should have known this by having used other functions like listSubscribe? It is not a problem or strange that this is not properly documented in the API?

firfin

unread,
Jan 30, 2013, 9:19:07 AM1/30/13
to mailchimp-...@googlegroups.com
Unfortunately I am still getting errors on both campaignUpdate AND segmentTest.
$mcapi is a mailchimp API object. $cid a valid Campaign ID. $settings['list_id']
If I remove the lines trying to update or test the segments everything works fine.


The interest grouping IDs and names come from listInterestGroup.

When using $mcapi->campaignSegmentTest($settings['list_id'], $opts);  or
When using $mcapi->campaignUpdate($cid, 'segment_opts', $opts);

MailChimp error code: 506, MailChimp error message: op="one" is invalid for field="interest" and value="vip1".

What does this mean? It isnt possible to just select 1 checkbox?
The doc states:  Valid Op(erations): one / none / all
Why do I get an error?


Using the following $opts array:
Array
(
    [match] => any
    [conditions] => Array
        (
            [0] => Array
                (
                    [field] => interest-13321
                    [op] => one
                    [value] => vip1
                )
            [1] => Array
                (
                    [field] => interest-13481
                    [op] => one
                    [value] => group two,gruppe drei
                )
        )
)

jesse

unread,
Jan 30, 2013, 10:06:27 AM1/30/13
to mailchimp-...@googlegroups.com
Yes - I've updated the docs to be more specific for folks diving in head first. That's always been properly documented - along with examples - in listSubscribe which, frankly, is where most people start.


jesse

jesse

unread,
Jan 30, 2013, 10:08:37 AM1/30/13
to mailchimp-...@googlegroups.com
It means that you used an invalid operation based on the field name you passed, and you definitely did - "interest-X" instead of "interests-X".


jesse

firfin

unread,
Jan 30, 2013, 11:28:59 AM1/30/13
to mailchimp-...@googlegroups.com
DOH!
Thansk for pointing that out Jesse. I guess the error threw me of. All I was thinking was what is wrong with op='one' as the error states. While actually the problem was an invalid field.

firfin

unread,
Jan 30, 2013, 11:32:13 AM1/30/13
to mailchimp-...@googlegroups.com
Thanks for updating the docs. Hopefully is will save someone else the hours I sank into this.
I don't need listsubscribe for my scenario. People sign themselves up for their list and associated interests. I just need to create campaigns from CMS content. So I for one never woudl have thought to look at listSubscribe() .

Thanks again for clarifying!
Reply all
Reply to author
Forward
0 new messages