MailchimpLists->updateSegment() has Improper Parameters
Opened this issue · 3 comments
According to the documentation for adding/removing users to a static segment the parameters members_to_add
and members_to_remove
are the only (optional) parameters to be used towards this execution.
The only assured parameter is the name of the segment - which should only be passed in when creating a new segment.
I've noticed this using Drupal 7.55 and MailChimp 7.x-4.8.
When attempting to rewrite the mailchimp_segment_batch_add_subscribers()
function to have the proper parameters as specified in the above documentation I was returned with zero errors and zero successes.
Logging Mailchimp->handleRequest()
returns the following:
Method: PATCH
URI: 'https://us15.api.mailchimp.com/3.0/lists/{list_id redacted}/segments/{segment_id redacted}'
Options:
Array
(
[headers] => Array
(
[Authorization] => apikey {api_key redacted}
)
[json] => stdClass Object
(
[members_to_add] => Array
(
[0] => {valid email redacted}
)
[name] => Freddie's peeps
)
)
Looks like we missed some functionality because MailChimp's API uses same endpoint for updating a segment and adding members to a segment.
MailchimpLists->updateSegment() is based on this documentation
The difference is this line specifies the PATCH method instead of POST, which would be used to add or remove members.
So we could use new functions. How do MailchimpLists->addSegmentMembers($members)
and MailchimpLists->removeSegmentMembers($members)
sound?
Apart from the POST and PATCH problem, I also noticed converting to an object seemed flawed. View #59 for how I solved the problem.