Problems with the MailChimp API in Ruby Error Code: -90

I use the following code in my MailChimp Controller to send simple newsletters. When it is sent, I get the following error, because "The method is not exported by this server -90." I have added my controller code below. I use this controller for a simple newsletter registration form. (Name, Email)

class MailchimpController < ApplicationController

  require "net/http"
  require "uri"

  def subscribe  
    if request.post?
      mailchimp = {}
      mailchimp['apikey']  =  'f72328d1de9cc76092casdfsd425e467b6641-us2'
      mailchimp['id']  =  '8037342dd1874'
      mailchimp['email_address']  =  "email@gmail.com"
      mailchimp['merge_vars[FNAME]']  =  "FirstName"
      mailchimp['output']  =  'json'

      uri = URI.parse("http://us2.api.mailchimp.com/1.3/?method=listSubscribe")
      response = Net::HTTP.post_form(uri, mailchimp)    
      mailchimp = ActiveSupport::JSON.decode(response.body)

      if mailchimp['error']
        render :text =>    mailchimp['error'] + "code:" + mailchimp['code'].to_s  
      elsif mailchimp == 'true'
        render :text => 'ok' 
      else
        render :text => 'error'
      end
    end
   end    

end
+5
source share
3 answers

I highly recommend Hominid Stone: https://github.com/tatemae-consultancy/hominid

+4
source

, Net:: HTTP.post_form "" GET. , , Net:: HTTP, :

require "net/http"
data="apikey=blahblahblah"
response = nil
Net::HTTP.start('us2.api.mailchimp.com', 80) {|http|
  response = http.post('/1.3/?method=lists', data)
}
p response.body

lists() ( ), ( urlencode !) POST, .

, ?

http://apidocs.mailchimp.com/downloads/#ruby

, , , API- . , , . , , , - . , , .

+2

You can use your hash if you convert it to json before passing it to Net :: HTTP. The combined code will look something like this:

  mailchimp = {}
  mailchimp['apikey']             =  'APIKEYAPIKEYAPIKEYAPIKEY'
  mailchimp['id']                 =  '8037342dd1874'
  mailchimp['email_address']      =  "email@gmail.com"
  mailchimp['merge_vars[FNAME]']  =  "FirstName"
  mailchimp['output']             =  'json'

  response = nil
  Net::HTTP.start('us2.api.mailchimp.com', 80) {|http|
    response = http.post('/1.3/?method=listSubscribe', mailchimp.to_json)
  }
+1
source

All Articles