← Back to Upcase

How update all fields in MailChimp batch subscribe using Ruby and Gibbon


(Jason Pierce) #1

I am using Ruby 1.9.3 without Rails and version 1.0.4 of the Gibbon gem.

I have referrals populated with my list and can send the following to MailChimp with Gibbon. However, only the email address and email type fields are populated in the list in MailChimp. What am I doing wrong that is prohibiting all the merge fields from being imported via API?

Here is the batch and map of the list.

referrals.each_slice(3) do |batch|
  begin
    prepared_batch = batch.map do |referral|
      { 
        :EMAIL => {:email => referral['client_email']}, 
        :EMAIL_TYPE => 'html', 
        :MMERGE6 => referral['field_1'],
        :MMERGE7 => referral['field_2'],
        :MMERGE8 => referral['field_3'],
        :MMERGE9 => referral['field_4'],
        :MMERGE11 => referral['field_5'],
        :MMERGE12 => referral['field_6'],
        :MMERGE13 => referral['field_7'],
        :MMERGE14 => referral['field_8'],
        :MMERGE15 => referral['field_9'],
        :FNAME => referral['client_first_name']
      }
    end
    @log.info("prepared_batch : #{prepared_batch}")

result = @gibbon.lists.batch_subscribe(
  :id => @mc_list_id, 
  :batch => prepared_batch,
  :double_optin => false,
  :update_existing => true
)
@log.info("#{result}")

  rescue Exception => e
    @log.warn("Unable to load batch into mailchimp because #{e.message}")
  end
end

The above executes successfully. However, only the email address and email type are populated but most of the fields should be populated.

Here is my log output for one of the prepared_batches. I replaced the real values with Value. I used my own email for testing.

I, [2013-11-11T09:01:14.778907 #70827]  INFO -- : prepared_batch : [{:EMAIL=>
{:email=>"jason+6@marketingscience.co"}, :EMAIL_TYPE=>"html", :MMERGE6=>"Value",
 :MMERGE7=>"Value", :MMERGE8=>nil, :MMERGE9=>nil, :MMERGE11=>"8/6/13 0:00",
 :MMERGE12=>"Value", :MMERGE13=>nil, :MMERGE14=>"10/18/13 19:09", :MMERGE15=>"Value",
 :FNAME=>"Value"}, {:EMAIL=>{:email=>"jason+7@marketingscience.co"}, :EMAIL_TYPE=>"html",
 :MMERGE6=>"Value", :MMERGE7=>"Value", :MMERGE8=>nil, :MMERGE9=>nil, :MMERGE11=>"8/6/13
 0:00", :MMERGE12=>"Value", :MMERGE13=>nil, :MMERGE14=>nil, :MMERGE15=>"Value",
 :FNAME=>"Value"}, {:EMAIL=>{:email=>"jason+8@marketingscience.co"}, :EMAIL_TYPE=>"html",
 :MMERGE6=>"Value", :MMERGE7=>"Value", :MMERGE8=>nil, :MMERGE9=>nil, :MMERGE11=>"8/7/13
 0:00", :MMERGE12=>"Value", :MMERGE13=>nil, :MMERGE14=>nil, :MMERGE15=>"Value",
 :FNAME=>"Value"}]

Here is the log output of result from the MailChimp call.

I, [2013-11-11T09:01:14.778691 #70827]  INFO -- : {"add_count"=>3, "adds"=>
[{"email"=>"jason+3@marketingscience.co", "euid"=>"ab512177b4", "leid"=>"54637465"},
 {"email"=>"jason+4@marketingscience.co", "euid"=>"eeb8388524", "leid"=>"54637469"},
 {"email"=>"jason+5@marketingscience.co", "euid"=>"7dbc84cb75", "leid"=>"54637473"}],
 "update_count"=>0, "updates"=>[], "error_count"=>0, "errors"=>[]} 

Any advice on how to get all the fields to update in MailChimp is appreciated. Thanks.


(Jason Pierce) #2

I found out the documentation for the gibbon gem is not up-to-date. I needed to add a :merge_vars struct into the call and then everything worked correctly. Full working example is here: https://gist.github.com/analyticsPierce/7434085