Created
April 6, 2021 17:51
-
-
Save hrishimittal/98836e78266c9f7cadc8721d95008d55 to your computer and use it in GitHub Desktop.
Add email to Mailchimp group via API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add_to_mailchimp_group(email) | |
gibbon = Gibbon::Request.new | |
gibbon.lists('some_list_id') | |
.members(Digest::MD5.hexdigest(email.downcase).downcase) | |
.upsert(body: { | |
email_address: email, | |
status: "subscribed", | |
interests: {'some_group_id' => true}, | |
merge_fields: {"MERGE1" => 'merge_field_value'} | |
}) | |
rescue Gibbon::MailChimpError => e | |
#Handle the error | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment