简体   繁体   中英

Mailchimp API CURL - Auto-subscribe user with Groupings

I am trying to auto-subscribe a user when they click on "Subscribe to Newsletter" on my website's signup form.

I have the CURL built up and it works, but I need to configure it to add the user's registration type into Mailchimp.

When the user signs up, we ask them if they drive a "taxi", "car", "bus", "truck" or "motorcycle". In Mailchimp I have a group called "Transit" with the above options.

This is the current CURL command I am using:

    $apikey = "MY API KEY";
    $merge_vars = Array( 
        'FNAME' => $fname, 
        'LNAME' => $lname,
        'GROUPINGS'=>array(
            array('name'=>'Transit:', 'groups'=>'car')
        )
    );
    $listID = 'MY LIST ID'; 
    $email = $email;
        $url = sprintf('http://us11.api.mailchimp.com/1.2/?method=listSubscribe&apikey=%s&id=%s&email_address=%s&merge_vars[OPTINIP]=%s&merge_vars[MERGE1]=%s&merge_vars[MERGE2]=%s&output=json', $apikey, $listID, $email, $merge_vars, $merge_vars['FNAME'], $merge_vars['LNAME'], $_SERVER['REMOTE_ADDR']);
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $data = curl_exec($ch);
        curl_close($ch);

When the user signs up, it doesn't store that they drive a car in the transit groupings.

Step 1 should really be using a version of the API that isn't 8 years old and deprecated!

In the latest version , this is simply done by using an interests parameter on the list member add call . You'll grab the interest IDs for each of your options ('car', 'truck', etc..) and then your member object looks like this:

{
  "email_address": "some_address@mail.com",
  "status": "subscribed",
  "interests": {
    "abc123": true,
    "def456": false
  }
}

Where abc123 and def456 are the IDs of the interests you're using.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM