Ecwid / ecwid-mailchimp

MailChimp API Wrapper for Java
Apache License 2.0
86 stars 83 forks source link

Example of setting or updating the grouping information on a subscriber #24

Open ghost opened 10 years ago

ghost commented 10 years ago

Hi,

First, thanks for the library — I’d be dead in the water without it.

Second, I’d like to reopen the very first issue/question raised [#1 Updating grouping for existing or new subscriber]: It would be great if you could include an example (e.g. in the unit tests) of setting or updating the grouping information on a subscriber, for instance when adding a new subscriber via listSubscribe using GROUPINGS in merge_vars.

The problem is that the link in the response to that question is broken:

https://github.com/Ecwid/ecwid-mailchimp/blob/master/src/test/java/com/ecwid/mailchimp/method/list/InterestGroupingMethodsTest.java

And in the current download, there are no tests, only a folder containing logging.properties.

I’ve gotten the basic ‘subscribe a person to a list’ working following your wiki code. But I can’t work out how to utilize/combine the various [List]InterestGroup[ings]Method objects with SubscribeMethod or UpdateMemberMethod.

Regards, Ken

jo-elimu commented 8 years ago

Hi, I'm struggling with the same thing. I'm iterating to the relevant MemberInfoGroups, update them, and execute the request, but the changes are not reflected on the MailChimp server...

    UpdateMemberMethod updateMemberMethod = new UpdateMemberMethod();
    updateMemberMethod.apikey = API_KEY;
    updateMemberMethod.id = LIST_ID;
    updateMemberMethod.email = new Email();
    updateMemberMethod.email.email = email;

    MemberInfoData memberInfoData = new MailChimpSubscriptionHelper().getMemberInfoData(email);
    List<MemberInfoGrouping> memberInfoGroupings = (List<MemberInfoGrouping>) memberInfoData.merges.get("GROUPINGS");
    for (MemberInfoGrouping memberInfoGrouping : memberInfoGroupings) {
        // Update relevant MemberInfoGroups (set attribute "interested" = true)
    }
    logger.info("memberInfoGroupings: " + memberInfoGroupings);
    MailChimpObject mergeVars = new MailChimpObject();
    mergeVars.put("GROUPINGS", memberInfoGroupings.toString());
    updateMemberMethod.merge_vars = mergeVars;

    updateMemberMethod.replace_interests = true;

    MailChimpClient mailChimpClient = new MailChimpClient();
    try {
        mailChimpClient.execute(updateMemberMethod);
    } catch (IOException | MailChimpException ex) {
        logger.error(null, ex);
    }
kejdiB commented 4 years ago

you have to include the API_KEY into mialchimp client MailChimpClient mailChimpClient = new MailChimpClient(lYOUR_API_KEY);