1

I am trying to implement call this API method in Ruby https://zferral.com/api-docs/affiliate#aff-create-usage-example which expects this object:

{  "affiliate" : {
    "email"           : "[email protected]",
    "send_user_email" : "1" }}

Using a Httparty class, I call this:

result = self.class.post("/api/#{@apikey}/affiliate/create.xml", :body => {:affiliate => {:email => email}})

Unfortunately, the API keeps sending me "Email is required". I have tried to switch to json, I am changed :body with :query, etc...

Anybody could show me how to call the affiliate/create method correctly?

Thank you.

2 Answers 2

2

You're sending json, but posting it to create.xml --- in rails, this will auto-set the content type to be xml when you post to create.xml

Try posting to /api/#{@apikey}/affiliate/create.json

If that doesn't work --- are you following the class design that HTTParty really likes? http://railstips.org/blog/archives/2008/07/29/it-s-an-httparty-and-everyone-is-invited/

Sign up to request clarification or add additional context in comments.

Comments

2

This is how I fixed my issue:

    url = URI.parse('https://xxxx.zferral.com/api/xxx/affiliate/create.xml')
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    request = Net::HTTP::Post.new(url.path)
    request.body = "<?xml version='1.0' encoding='UTF-8'?><affiliate><email>#{email}</email><send_user_email>0</send_user_email></affiliate>"
    request.content_type = 'text/xml'
    response = http.request(request)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.