Reputation: 89
I'd like to create a mailchimp campaign for a subsets of an email list by filtering the list on a tag ('test_tag') that I've applied to the intended subset. I'm not sure what the correct syntax is for this. I can't find any documentation on how to programmatically create anything using tags.
I can successfully achieve emailing the subset of my list using the 'prebuilt_segment_id' feature. I created a segment called 'test_segment'.
The following code works:
curl --request POST \
--url 'https://us18.api.mailchimp.com/3.0/campaigns' \
--user 'anystring:12345667889qwerty' \
--header 'content-type: application/json' \
--data '{"recipients":{"list_id":"123abc", "segment_opts":{"prebuilt_segment_id":"test_segment"}},"type":"regular","settings":{"subject_line":"Your Purchase Receipt", "reply_to":"orders@mammothhouse.com","from_name":"Customer Service"}}' \
--include
What would the syntax be for using my tag 'test_tag' instead of my segment (assume that every member in the 'test_segment' has the tag of 'test_tag')?
The following code does not work:
curl --request POST \
--url 'https://us18.api.mailchimp.com/3.0/campaigns' \
--user 'anystring:12345667889qwerty' \
--header 'content-type: application/json' \
--data '{"recipients":{"list_id":"123abc", "segment_opts":{"conditions":[ { "condition_type":"Tag", "field":"tag", "op":"is", "value":"test_tag" }]},"type":"regular","settings":{"subject_line":"Your Purchase Receipt", "reply_to":"orders@mammothhouse.com","from_name":"Customer Service"}}' \
--include
Any help with this or any examples of using tags to create something using the api would be much appreciated (eg, can I create a segment using tags?)
Upvotes: 4
Views: 472
Reputation: 193
According to Mailchimp (see StaticSegment), StaticSegments are now Tags, so here's the proper way to create your conditions array when you want to segment by tag:
'conditions' => [
[
'condition_type' => 'StaticSegment',
'field' => 'static_segment',
'op' => 'static_is',
'value' => $tagId
]
]
Keep in mind that you need to get the tag id in advance in order for this to work. There is API in the docs on how to do it.
Upvotes: 0