title: How to subscribe new users with Mailchimp API 3.0 and Gibbon 2.x
body: <p>In my app I want to auto-subscribe users to a MailChimp list when they are created. All of the documentation I have found focuses on MailChip API 2.0 and Gibbon 1.x. </p>
  
  <p>Here is what I have so far:</p>
  
  <p>I created a .env file with: </p>
  
  <pre><code>MAILCHIMP_API_KEY = "my_api_key"
  MAILCHIMP_LIST_ID = "my_list_id"
  </code></pre>
  
  <p>I created an initializer called gibbon.rb with:</p>
  
  <pre><code>Gibbon::Request.api_key = ENV["MAILCHIMP_API_KEY"]
  Gibbon::Request.timeout = 15
  </code></pre>
  
  <p>Then created a Job:</p>
  
  <pre><code>class SubscribeUserToMailingListJob &lt; ActiveJob::Base
    queue_as :default
  
    def perform(user)
      gibbon = Gibbon::Request.new
      # I am getting errors from this line
      gibbon.lists(ENV["MAILCHIMP_LIST_ID"]).members.create(body: {email_address: user.email, status: "subscribed", merge_fields: {FNAME: user.name, LNAME: ""}})
    end
  end
  </code></pre>
  
  <p>In my user.rb I've this after check</p>
  
  <pre><code>after_create :subscribe_user_to_mailing_list
  </code></pre>
  
  <p>And added this under private:</p>
  
  <pre><code>def subscribe_user_to_mailing_list
    SubscribeUserToMailingListJob.perform_later(self)
  end
  </code></pre>
  
  <p>I am getting a 400 error from <code>gibbon.lists(ENV["MAILCHIMP_LIST_ID"]).members.create(body: {email_address: user.email, status: "subscribed", merge_fields: {FNAME: user.name, LNAME: ""}})</code></p>
  
  <p>********EDIT********</p>
  
  <p>Per this <a href="https://github.com/amro/gibbon/issues/121" rel="nofollow">conversation</a>.</p>
  
  <p>I think the error was occurring because the email address already existed in the list. The first time I got an error, the email address was added to the MailChimp list but the user was not created in my app due to another bug. Now when I try to create a user with the same email address the error 400 pops up because the email already exists. This also prevents the user from being created in my app. </p>
  
  <p>Can somebody with a little more experience please verify if this is correct?</p>