0

I've spent the last day trying to get this to work in my Rails app, but continually get the response:

{"code"=>"E-C-343", "message"=>"Unrecognized JSON Request."}

BancBox's Documentation is pretty light, so I'm at a bit of an impasse on how to solve this.

Does anyone have an example of a successful API call to createClient at BancBox utilizing REST?

My Post API call utilizing HTTParty:

include HTTParty
format :json

def save_with_bancbox(params = {})

  post_params = { :authentication =>  { :apiKey => BANCBOX_KEY,
                                        :secret => BANCBOX_SECRET
                                        },
                  :subscriberId => BANCBOX_ID,
                  :firstName => params[:first_name],
                  :lastName => params[:last_name],
                  :ssn => params[:ssn],
                  :dob => params[:dob],
                  :address => { :line1 => params[:address_line_1],
                                :line2 => params[:address_line_2],
                                :city => params[:city],
                                :state => params[:state],
                                :zipcode => params[:zipcode]
                                },
                  :homePhone => params[:dob],
                  :email => params[:email]
                  }

  response = HTTParty.post( BANCBOX_REST_URL, 
                            :body => post_params)

    logger.debug "Response -- #{response}"

  save!

end
Will Palmer
  • 5,742
  • 1
  • 26
  • 33
Stephen Sprinkle
  • 1,015
  • 11
  • 14
  • I've ended up going the SOAP route and everything is working well. Leaving the question open since I'm curious to learn how to do this correctly and hopefully it'll be valuable to someone in the same position I was. – Stephen Sprinkle Jul 26 '12 at 00:37

2 Answers2

2

Please try the below code after changing apikey, secret and subscriberid


require "net/https"

require 'rubygems'

require 'json'

require 'httparty'


###########################bancbox.rb in config/initializers#################

BANCBOX_API_KEY = "__KEY__"

BANCBOX_API_SECRET = "__SECRET__"

BANCBOX_SUBSCRIBER_ID = "__SUB_ID__"

BANCBOX_API_URL = "https://sandbox-api.bancbox.com/BBXPortRest"

module Bancbox

        class API

                include HTTParty 
                debug_output $stdout
                base_uri "#{BANCBOX_API_URL}"

                def initialize(u=BANCBOX_API_KEY,p=BANCBOX_API_SECRET)
                        auth = {:apiKey => u, :secret => p}
                        @options = {:body => {:authentication =>auth,:subscriberId=>BANCBOX_SUBSCRIBER_ID}, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }}
                end

                #USERS
                def create_client(options={})  
                        options = options.merge(@options[:body])
                        @options.merge!({:body => options.to_json})
                        response = self.class.post("/createClient",@options)
                        #required_fields- subscriberId,firstName,lastName,ssn,dob,address,homePhone,email
                end

                def get_schedules(options={})
                        @options.merge!({:query => {:subscriberId => BANCBOX_SUBSCRIBER_ID}})
                        @options.merge!({:query => options})
                        self.class.post("/getSchedules",@options)
                end
        end
end

b = Bancbox::API .new


b.create_client({:firstName=> "Bipen",:lastName=> "Sasi",:ssn=>"334-444-4444",:dob=> Date.parse("January 1st 1988"), :address=>{:line1=> "4408 walnut st", :line2=>"apt 3r",:city=> "philly",:state=>"pa",:zipcode=>"19110"}, :homePhone=> "2672551161",:email=>"bipen@lokalty.com"})
deadly
  • 1,194
  • 14
  • 24
Prashant
  • 36
  • 2
0

I think you should POST the request to

https://sandbox-api.bancbox.com/BBXPortRest/createClient

instead of

https://sandbox-api.bancbox.com/BBXPortRest/

Also make sure to set the content type as application/json

In general, you post your request to https://sandbox-api.bancbox.com/BBXPortRest/<method>

Ed Solis
  • 41
  • 5
  • Can't say if this would fix the problem this second, let me checkout an old commit and get back to you. – Stephen Sprinkle Aug 15 '12 at 03:47
  • This did not fix the issue..were you able to solve this problem @StephenSprinkle? – bpn Sep 18 '12 at 14:06
  • @bpn, not with REST. I'm still encountering the same issue with the new URL suggested by Ed using the various appended methods. Ed Solis, would you mind posting the full method you use in rails for the api post call? That might give me some more insight into debugging the call on my end. – Stephen Sprinkle Sep 30 '12 at 05:27