Reputation: 565
What do I have to do in order to send a user's name and email to my Mailchimp account automatically as soon as they sign up on my application (Devise)?
Upvotes: 0
Views: 140
Reputation: 665
I like to use Gibbon, a mailchimp wrapper to work with their api
def add_to_mailchimp(email_address, first_name, last_name)
list_id = "your_list_id"
gibbon = Gibbon::Request.new
# only need the md5_email if you want to use 'upsert' (find_or_create_by) or 'update', not 'create'
md5_email = Digest::MD5.hexdigest(email_address)
gibbon.lists(list_id).members(md5_email).upsert(body: {email_address: email_address, status: "subscribed", merge_fields: {FNAME: first_name, LNAME: last_name}})
end
Upvotes: 1
Reputation: 720
you probably should use the regular User after create hook
class User < ActiveRecord::Base
after_create :send_to_mailchimp
def send_to_mailchimp
# send data to mailchimp
end
end
Upvotes: 1