4

i've looked around for this for a long time but couldn't find any answer. In my rails 4 app i'm using the Gibbon gem (v.2.0.1) to manage mailchimp lists. Everything works fine as far as subscribing and unsunscribing users, but i cannot manage to update the email address of a subscribed user (i can change every parameter like first and last name though).

my update call looks something like:

member = $gibbon.lists(list_id).members(member_id)
member.update(body: 
              { email_address: self.email,
                status: "subscribed",
                merge_fields: {FNAME: self.first_name,
                               LNAME: self.last_name}
               }
               )

i've tried upsert as well but no luck. Is is actually possible to update emails in mailchimp or do i need to delete the user and create a new one? thanks for the help

user3623363
  • 101
  • 6
  • You say you can delete people from the list, but are you doing this by member ID, or by email address? I can't find a way to do it by email address, which is what I have. Are you tracking the user's MailChimp ID to use for unsubscription? If not, have you found a method to find the user's ID from the list (by email address) so as to be able to delete them? – David Krider Nov 23 '15 at 22:11
  • 1
    To unsubscribe from MailChimp you must do `gibbon.lists(list_id).members(lower_case_md5_hashed_email_address).update(body: { status: "unsubscribed" })` as explained in [Gibbon's docs](https://github.com/amro/gibbon#subscribers). I store the `lower_case_md5_hashed_email_address` as a `:mc_member_id` in my User model. – Pietro Feb 11 '16 at 08:51

2 Answers2

2

Editing addresses is sort of possible in the web app and in some older versions of the API, but it's tricky because most of the address's history doesn't follow after the change. Deleting or unsubscribing and then adding the new address is likely the best way.

TooMuchPete
  • 4,583
  • 2
  • 17
  • 21
2

After some extra research and contacting Mailchimp i can confirm that with the new api (v3.0) it is not possible to edit the email address as it is a read only field. As a solution i ran a method to specifically edit the email address, which basically retrieve the member in Mailchimp (i'm storing the mailchimp id in my db within the User model), deletes it and creates a new one with the same data (for instance, if the member is unsubscribed the new one will be unsubscribed as well). As the email address changed needs to be confirmed through an email link (i'm using Devise), i've added a resque task in the registrations controller to do execute my method. hope that helps somebody else

user3623363
  • 101
  • 6