Help us understand the problem. What is going on with this article?

ecwid-mailchimpでListにSubscribersを追加する時にGroupsも指定する方法

More than 5 years have passed since last update.

事前にGroupsを以下のように作っておく。

List Groups for Example   MailChimp.png

Javaコードの中では、GROUPINGSというフィールドで上記Groupsを扱える。

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ecwid.mailchimp.MailChimpClient;
import com.ecwid.mailchimp.MailChimpException;
import com.ecwid.mailchimp.MailChimpObject;
import com.ecwid.mailchimp.method.list.ListSubscribeMethod;

public class Example {

    @SuppressWarnings("serial")
    public static class MergeVars extends MailChimpObject {
        @Field
        public String EMAIL, FNAME, LNAME;

        @Field
        public List<Map<String, Object>> GROUPINGS = new ArrayList<>();

        public MergeVars() {
        }

        public MergeVars(String email, String fname, String lname, String groups) {
            this.EMAIL = email;
            this.FNAME = fname;
            this.LNAME = lname;
            Map<String, Object> group = new HashMap<>();
            group.put("name", "Exmple Groups");
            group.put("groups", groups);
            GROUPINGS.add(group);
        }
    }

    public static void main(String[] args) throws IOException,
            MailChimpException {
        MailChimpClient mailChimpClient = new MailChimpClient();

        ListSubscribeMethod listSubscribeMethod = new ListSubscribeMethod();
        // ここにAPI Keyを入れる。
        listSubscribeMethod.apikey = "****";
        // ここにリストIDを入れる。
        listSubscribeMethod.id = "****";
        // メールアドレスは実在するものを使うこと。このまま使うとエラーになる。
        listSubscribeMethod.email_address = "ryu22e@example.com";
        listSubscribeMethod.double_optin = false;
        listSubscribeMethod.update_existing = true;
        listSubscribeMethod.merge_vars = new MergeVars("ryu22e@example.com",
                "Ryuji", "TSUTSUI", "group1");
        mailChimpClient.execute(listSubscribeMethod);
    }

}

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away