Wednesday, March 28, 2007

NetSuite and Ruby, the final chapter

NetSuite requires a maintainable session for subsequent requests after the initial login by way of several cookies they return upon successful authentication. The standard Net::HTTP library requires mucking with headers by hand in order to perpetuate cookie information. We were easily able to override SOAP::NetHttpClient::Response and SOAP::HTTPStreamHandler in the soap4r gem in order to provide the functionality for maintaining the NetSuite session.

, NaHi's http-access2 library already provides cookie management (even persistence if needed). After installing visnu's gem it's simply a matter of turning off the SSLConfig#verify_mode and everything works flawlessly. The final test code:
require 'rubygems'
require_gem 'soap4r'
require 'defaultDriver' #generated by soap4r
require 'pp'

driver =
driver.wiredump_dev = STDOUT
driver.proxy.streamhandler.client.ssl_config.verify_mode = nil

passport = = ''
passport.password = '123123123'
passport.account ="123123"
passport.role =
passport.role.xmlattr_internalId = '123123123'


record =
record.xmlattr_internalId = '123123123'
record.xmlattr_type = RecordType::Customer

pp driver.get(

Everything said and done, this has been a good learning experience. But more than anything it has exposed one of the Ruby community's greatest weaknesses: documentation. I've known this since the beginning of my Ruby days (2004) and have grown accustomed to reading code. Nevertheless, that takes time, and usually more time than scanning decently-documented APIs. The other side of this story is that I understand the Japanese/English language barrier which may intimidate or otherwise prevent library maintainers from providing more documentation. In the end, Ruby is a community-driven language, which is not sponsored by massive corporate dollars (cough, Java, cough, .Net) and its beginnings have solid Japanese roots. Here's to hoping that documentation improves as more libraries become available and the language matures. In the mean time, thank goodness for Google, mailing lists, blogs and IRC. I believe that documentation practices exhibited by 37Signals and the Rails community are the guiding example, they're not perfect, but the situation continues to progress.


Jim Kane said...

Thanks for the posts on Netsuite and Ruby -- we are investigating Netsuite right now (with php, meh) but seeing that Ruby works OK with it brings a smile to my face.

RR said...

Glad to hear it, Jim! Our CRM application is almost complete and we've had our fair share of pain when dealing with NetSuite's API. I may write up a rant after we release to describe our pain points--mostly due to their erroneous documentation, missing features and typically-lengthy response time to API bugs.

Adam Maddox said...

Thanks for the post. I would love to hear those pain points, we're currently investigating their service for inventory and financials. Ever few lines of NetSuite documentation i read a voice in my head asks 'where is the rest api, seriously'!