getting csv data from RTC using form based authentication

I’ve been playing with ways to get CSV data from an RTC server.  Here’s how to get the CSV file related to a query when the server uses forms based authentication.  The following code snippet shows how to get the CSV file associated with an RTC query.

Apart from knowing your userid and password you also need to know the query id.  That’s a lovely string that looks something like  _UkgjwLDcEeO2Eca4475iNQ and usually makes up a portion of the RTC query url.

Assuming you’ve got them then this sort of  code does the trick.


require 'mechanize'
require 'nokogiri'
require 'linkeddata'

mechanize=Mechanize.new

userid=ARGV[0]
password=ARGV[1]
queryid=ARGV[2]

host="https://jazz802.hursley.ibm.com:9443/ccm"
authformpage=host+'/authenticated/j_security_check'
page=mechanize.get(host+'/resource/itemOid/com.ibm.team.workitem.query.QueryDescriptor/'+queryid+'?_mediaType=text/csv')
data=mechanize.post(authformpage,{ 'j_username' => userid , 'j_password' => password}).body

puts data
Advertisements

About spoole167

I'm DevOps practitioner (whatever that means), a long time Java developer and Open Source advocate. I speak and present at conferences whenever I have something to say on technical and software engineering topics. I work for IBM but this blog is all my own work.
This entry was posted in CODE, RUBY, Uncategorized and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s