mailchimp-api-php icon indicating copy to clipboard operation
mailchimp-api-php copied to clipboard

MailchimpLists->updateSegment() has Improper Parameters

Open collinhaines opened this issue 7 years ago • 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
        )
)

collinhaines avatar Jun 09 '17 14:06 collinhaines

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?

ruscoe avatar Jun 27 '17 05:06 ruscoe

I just noticed issue #60 needs the same solution.

ruscoe avatar Jun 27 '17 05:06 ruscoe

Apart from the POST and PATCH problem, I also noticed converting to an object seemed flawed. View #59 for how I solved the problem.

collinhaines avatar Jul 01 '17 01:07 collinhaines