简体   繁体   中英

How I can add subscriber to couple lists in MailChimp via API?

I want to create couple lists in mailchimp, and I need to have some users in couple lists. I successfully added user to first list, but can't add to second, because I get an error "This user is already subscribed".

I read about segmentation but this doesn't resolve issue, also I see that there is a posibility to copy user from one list to another via mailchimp admin panel, but I can't find which method can do this is in API v2.0

function cog_add_user_email_mailchimp( $user_id ) {
$user_data = get_userdata( $user_id );

if ( is_object( $user_data ) && ! empty( $user_data->user_email ) ) {
    $mailchimp_obj = new COG_Mailchimp_Newsletters( MAILCHIMP_APIKEY );
    $mailchimp_obj->user_id = $user_id;

    $result = $mailchimp_obj->subscibe_user( $mailchimp_obj->lists_id['all_user_list'], array( 'email' => $user_data->user_email ) );
    if ( $mailchimp_obj->check_user_subscribe_meta( $result ) ) {
        $mailchimp_obj->subscibe_user( $mailchimp_obj->lists_id['just_registered'],  array( 'euid' => $result['euid'] ) );
        $mailchimp_obj->init_compaing_object( $mailchimp_obj );
        $response = $mailchimp_obj->send_mail( $mailchimp_obj->lists_id['just_registered'] );
    }
}

}

Where: $mailchimp_obj->lists_id - array with lists id
$mailchimp_obj->subscibe_user - wrapper for subscribe method of mailchimp API

So I successfully add user into this list $mailchimp_obj->lists_id['all_user_list'], but when I try to subscribe into this list $mailchimp_obj->lists_id['just_registered'] I get an error.

Yes, you can. You'd better use segments inside the same list, though, as using separate lists count your subscribers twice (and, thus, increase the monthly bill).

Now, what have you tried so far? It is good practice to tell the community what code you have tried and didnt work. Or what did you google that yield no desired results but failed ones, etc.

The MailChimp API is a boon to work with. Read the docs.

http://apidocs.mailchimp.com/

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