Subscribing users with groups through MailChimp 2.0 API

徘徊边缘 提交于 2019-12-10 01:52:22

问题


I've been working on this problem for hours and can't seem to find the solution, hopefully someone can help!

I'm trying to create a simple MailChimp subscribe form on an HTTPS site and hence must use the API. I am using the "super simple mailchimp-api" PHP wrapper they suggest, and am trying to add my subscribers to interest groups based on checkboxes selected in the form. All the relevant checkboxes are named "group[]" so that PHP will POST them as an array.

I am passing the below to the wrapper:

$MailChimp = new MailChimp('api_key_removed');
$result = $MailChimp->call('lists/subscribe', array(
                'id'                => 'list_ID_removed',
                'email'             => array( 'email' => $_POST['email'] ),
                'merge_vars'        => array( 'FNAME' => $_POST['fname'], 'LNAME' => $_POST['lname'], 'COMPANY' => $_POST['company'], 'STATE' => $_POST['state'], 
                                    'GROUPINGS' => array(
                                        array( 
                                            'ID' => 14093, 
                                            'GROUPS' => $_POST['group']
                                        ) 
                                    )
                ),
                'double_optin'      => false,
                'update_existing'   => true,
                'replace_interests' => false,
                'send_welcome'      => true
            ));

When I test, the users are created correctly but no interest groups are selected. I have double checked that both the grouping ID and group names are correct. I have even tried hardcoding an array for GROUPS to no avail.

An example of the merge_vars $args passed to the API are:

[merge_vars] => Array
    (
        [FNAME] => Test
        [LNAME] => Test
        [COMPANY] => 
        [STATE] => TAS
        [GROUPINGS] => Array
            (
                [0] => Array
                    (
                        [ID] => 14093
                        [GROUPS] => Array
                            (
                                [0] => Invest
                                [1] => Deposit Bonds
                            )

                    )

            )

    )

From what I can understand this is exactly right, so I'm just not understanding where the problem lies. Can anyone see what I'm doing wrong? Or is the API broken?

Thanks

Josh


回答1:


I arrived at this "unanswered" question with zero answers, but found it was actually already answered in the comments of the question. I'm copying the comments to reflect the question has already received an answer.


OMG, after 5h I just discovered the problem! For anyone else stumped by this - the keys (not values) "groupings", "id" and "groups" all need to be lower case. I really don't understand why when all the other fields are documented everywhere as being uppercase and indeed work when they are uppercase. I assume it's some cruel joke they enjoy playing on developers. – Josh Nov 28 '13 at 12:37


In the older API versions they were in upper case. They changed it in 2.0. – Daniel Rikowski Mar 16 '14 at 21:49



来源:https://stackoverflow.com/questions/20266081/subscribing-users-with-groups-through-mailchimp-2-0-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!