سؤال

I'm using this Mailchimp 2.0 PHP wrapper:

https://github.com/drewm/mailchimp-api

To send data to my list via the Mailchimp 2.0 API.

I can get email, firstname, and lastname to send successfully from my form to mailchimp.

I set those up as required fields in mailchimp(EMAIL, FNAME, LNAME).

Here is the PHP for that:

$MailChimp = new MailChimp('xxxxxxx');
$result = $MailChimp->call('lists/subscribe', array(
'id'                => 'xxxxxx',
//required fields
'email'             => array( 'email' => $_POST['email']),
'merge_vars'        => array('FNAME' => $_POST['fname'], 'LNAME' => $_POST['lname']),
//mailchimp options
'double_optin'      => false,   
'update_existing'   => true,
'replace_interests' => false

));

But I also have 12 checkboxes for stuff like engine size, type, gas type, color, etc. that are optional.

How can send these to the mailchimp API? I'm hoping someone with experience with Mailchimp API could help out.

Any help would be appreciated.

Thanks!

هل كانت مفيدة؟

المحلول

Here is a clarification to the structure of the groupings that is not in the docs' example. I.e. you supply only the names of the groups that have been selected by the user:

"merge_vars": {
       "groupings": [
           {
               "groups": [
                   "selection 3",
                   "selection 7"
               ],
               "id": <group_id>// or "name": <group_name>
           }
       ]
   },

نصائح أخرى

In the merge_vars array, define "groupings" which points to an array. This 'groupings' array will then consist of individual arrays that point to a particular grouping of groups. Ex. if you have a grouping of groups titled "gas type" with group options "diesel", "unleaded", etc. this level of the array points to "gas type".

THEN, you define a "groups" array inside of this array to denote membership into the actual subgroups ("diesel", "unleaded").

Here's a code example from the list subscribe MailChimp API 2.0 documentation:

"merge_vars": {
        "groupings": [
            {
                "id": 42,
                "name": "example name",
                "groups": [
                    "..."
                ]
            }
        ]

lists/subscribe: http://apidocs.mailchimp.com/api/2.0/lists/subscribe.php

My personal suggestion: create groups in the web app if you haven't already. Then, use the lists/interest-groupings method to see how the interest groups are formatted and returned to you. This gives you a sense of how to structure it in your own code.

lists/interest-groupings: http://apidocs.mailchimp.com/api/2.0/lists/interest-groupings.php

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top