I'm trying to figure out how I can use the Gibbon gem in Rails to automatically add subscribers to specific interest groups in MailChimp?
I've found this article which details a non-Rails method for doing so: http://roman.tao.at/uncategorized/mailchimp-api-listsubscribe-listbatchsubscribe-and-groups/
I'd like to figure out how to implement that functionality using the Gibbon gem: https://github.com/amro/gibbon
FYI, I'm also a novice with both MailChimp and Rails.
Finally, after hours of perusing through code. I've found the example I'm looking for!
Thanks to TJ Moretto for providing this on a Google Groups thread:
I'm using the gibbon gem, but ran into the same types of issues. Here's how I had to format the parameters to finally get this to work:
gb.list_subscribe({:id => "#{list.id}", :email_address => user.email, :update_existing => true, :double_optin => false, :send_welcome => false, :merge_vars => {'FNAME' => "#{user.first_name}", 'LNAME' => "#{user.last_name}", 'GROUPINGS' => {0 => {'id' => grouping.id, 'groups' => "#{challenge.name}"}}} })
Hope that helps.
Mailchimp Team - based on the number of issues that everyone runs into when trying to do this (across all programming languages), I suggest you update the API documentation to be more clear.
Update for version 2.0 of the MailChimp API and version 1.0 of Gibbon (For @Calin and posterity). Here are the necessary changes from the previous version. The API object is accessed like this now:
gb = Gibbon::API.new
And list methods like so:
gb.lists.subscribe(params)
Finally the :email_address
parameter has been replaced by the :email
parameter, which should be given a value of the following form: The value should itself be a hash with one key, either 'email'
or 'leid'
, and the value should be either the email address of the subscriber or MC's unique identifier (LEID) for the subscriber.
So a full subscription call might look something like this:
gb = Gibbon::API.new
gb.lists.subscribe(:id => "ed6d1dfef4",
:email =>
{ "email" => "[email protected]" },
:merge_vars =>
{:groupings =>
{
0 => { :id => "95", :groups => ["Some Group", "Another Group"]},
1 => { :id => "34", :groups => ["A Third Group"]}
}
},
:update_existing => "true",
:double_optin => "false",
:replace_interests => "false")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With