ruby-on-railsrubyruby-on-rails-4mailchimpgibbon

"campaing_id" is not a symbol error when using mail chimp api with gibbon


Context: I have a rails application. I have a form where users can enter their email list to be a part of the news letter. I am using mail chimp and gibbon gem for rails. I can successfully add new subscribers to a list using the gibbon api I can successfully create a new campaign as shown in the code below. In my gem file : gem 'gibbon', git: 'git://github.com/amro/gibbon.git' For testing out the functionality, I invoke the create action in CampaignsController(code below). The campaign is created successfully and I get the result back from the api, but in the next step the app crashes with the following error message :

Problem: TypeError in CampaignsController#create ["xyz"] is not a symbol where xyz is the campaign_id of the newly created campaign.

Code: In CampaignsController

def create
    mailchimp = Gibbon::API.new(Rails.application.secrets.mailchimp_api_key)
    new_campaign = mailchimp.campaigns.create({:type=>"plaintext",
      :options=>
          {:list_id=>"abcdefgh",
          :subject=>"Hello World",:from_email => "xyz@gmail.com",
          :from_name => "abc",:to_name =>"Programmer"},  

          :content => 
          {:text => "Hello remote programmers I hope you find this mail."}        
      })

    cid = new_campaign["id"]
    mailchimp.campaigns.send(cid)
 end

Solution

  • It looks like mailchimp.campaigns.send is looking for a hash of options, not just an id.

    From their specs:

    expect(@gibbon.campaigns.send({"cid" => "1234567"})).to eq({"cid" => "1234567"})