When I save a campaign programmatically using the function mailchimp_campaign_save_campaign
And I want to have a new segments_opts without saved_segment_id specified, i'm getting:
An error occurred testing a list segment: 404: Resource Not Found - The requested resource could not be found.
The problem is in this part-
mailchimp\modules\mailchimp_campaign\mailchimp_campaign.module line 91:
// Test for valid list segment, if selected.
if (isset($recipients->segment_opts)) {
if (mailchimp_test_list_segment($recipients->list_id, $recipients->segment_opts->saved_segment_id) === NULL) {
return NULL;
}
}
And this function:
mailchimp_test_list_segment that requires a value for $recipients->segment_opts->saved_segment_id .
It should be an optional field, and in the case of missing this parameter- a new segment should be created.
From MailChimp documentation: campaigns -> recipients -> segment_opts -
https://developer.mailchimp.com/documentation/mailchimp/reference/campai...
segment_opts
An object representing all segmentation options. This object should contain a saved_segment_id to use an existing segment, or you can create a new segment by including both match and conditions options.
Example of $recipients variable to be sent to mailchimp_campaign_save_campaign function -
'list_id' => string '123'
'segment_opts' =>
'match' => 'any'
'conditions' =>
0 =>
'condition_type' => 'Interests'
'op' => string 'interestcontainsall'
'field' => string 'interests-1e2351'
'value' =>
0 => string 'a11'| Comment | File | Size | Author |
|---|---|---|---|
| #9 | saved-segment-id-optional-3079700-9.patch | 813 bytes | brendanthinkshout |
| #4 | saved-segment-id-optional-3079700-4.patch | 697 bytes | tamarpe |
Comments
Comment #2
tamarpe commentedComment #3
tamarpe commentedComment #4
tamarpe commentedComment #5
tamarpe commentedComment #6
firfin commentedI have tested this and it does circumnavigate the problem of saved_segment_id being hardcoded into the check. Problem solved.
Now I can continue my work on #2999677: Add support for Multiple Tags Thanks @tamarpe
But ..
Not sure if this is the correct way to solve the issue though, now we are not testing at all if 'saved_segement_id' is not present. Should we instead not test if there are 'match' and 'conditions' parameters in segment_opts? We can not really check if it is a valid segment though, because it has yet to be created.
Leaving this for the maintainers to decide.
Comment #7
firfin commentedRaising this to Major as this block use of any other segmentation (on of the main strengths of Mailchimp) than 'saved_segment_id'.
Comment #8
firfin commentedRelated a similar D7 issue.
Comment #9
brendanthinkshout commentedThanks to both of you for some good catches here. @firfin, is this patch what you had in mind?
Comment #10
brendanthinkshout commentedComment #11
firfin commentedI think that is a pretty good solution @brendanthinkshout. I will test the patch this week.
Comment #12
firfin commentedApplied cleanly and seems to lift the block for using something other than 'saved_segment_id'.
Thanks Brendan!
Comment #14
firfin commentedThis not totally done after all it seems ,follow-up in #3156283: Can not save campaign without 'saved_segment_id'
Also added issue about this same issue, but in D7 #3054670: Can't create new campaigns with non existing segmentation rules
Comment #15
brendanthinkshout commentedFollowing up in the @firfin's new issues.