Sample Code to do post and get requests using SpiraTeam Webservice using Ruby.

Tuesday, October 4, 2016
Avatar
Hi Guys,

I tried to perform a get request with SpiraTeam REST Webservice 5.0 with below code

<Snip>

require 'net/http'
require 'openssl'
require 'stringio'
require 'uri'
require 'zlib'
require 'rest_client'

response = RestClient.get 'http://api.inflectra.com/Spira/Services/v4_0/RestService.svc',{'username':'xxxxxxxx', 'api-key':'{xxxxxxx-xxxxx-xxxx-xxxx-xxxx-xxxxxxxx}', 'Content-Type':'application/json', 'accept':'application/json', }

puts response.body

</Snip>

This work fine and service gets created. However when i perform a 'GET' request like get the username with my user id present in SpiraTest I am getting 400 Bad Request error.

<Snip>

require 'net/http'
require 'openssl'
require 'stringio'
require 'uri'
require 'zlib'
require 'rest_client'

response = RestClient.get 'http://api.inflectra.com/Spira/Services/v4_0/RestService.svc/users/{xx:xxxx}',{'username':'xxxxxxxx', 'api-key':'{xxxxxxx-xxxxx-xxxx-xxxx-xxxx-xxxxxxxx}', 'Content-Type':'application/json', 'accept':'application/json', }

puts response.body

</Snip>

I am getting the below error

/usr/local/lib/ruby/gems/2.2.0/gems/rest-client-2.0.0/lib/restclient/abstract_response.rb:223:in `exception_with_response': 400 Bad Request (RestClient::BadRequest)

from /usr/local/lib/ruby/gems/2.2.0/gems/rest-client-2.0.0/lib/restclient/abstract_response.rb:103:in `return!'

from /usr/local/lib/ruby/gems/2.2.0/gems/rest-client-2.0.0/lib/restclient/request.rb:860:in `process_result'

from /usr/local/lib/ruby/gems/2.2.0/gems/rest-client-2.0.0/lib/restclient/request.rb:776:in `block in transmit'

from /usr/local/Cellar/ruby/2.2.3/lib/ruby/2.2.0/net/http.rb:853:in `start'

from /usr/local/lib/ruby/gems/2.2.0/gems/rest-client-2.0.0/lib/restclient/request.rb:766:in `transmit'

from /usr/local/lib/ruby/gems/2.2.0/gems/rest-client-2.0.0/lib/restclient/request.rb:215:in `execute'

from /usr/local/lib/ruby/gems/2.2.0/gems/rest-client-2.0.0/lib/restclient/request.rb:52:in `execute'

from /usr/local/lib/ruby/gems/2.2.0/gems/rest-client-2.0.0/lib/restclient.rb:67:in `get'

from webservicesample.rb:11:in `<main>


Moreover I am not able to perform any GET or POST request. Please help!!!!!!!!

2 Replies
Wednesday, October 5, 2016
Avatar
re: droidmann Tuesday, October 4, 2016
Tried the below url in soap UI still getting 'Request Error'

http://api.inflectra.com/Spira/Services/v5_0/RestService.svc/users?username=xxxxxxxx&api-key=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Can some one please help????
Wednesday, October 5, 2016
Avatar
re: droidmann Tuesday, October 4, 2016
Tried the below url in soap UI still getting 'Request Error'

http://api.inflectra.com/Spira/Services/v5_0/RestService.svc/users?username=xxxxxxxx&api-key=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Can some one please help????

Spira Helps You Deliver Quality Software, Faster and With Lower Risk

And if you have any questions, please email or call us at +1 (202) 558-6885

 

Statistics
  • Started: Tuesday, October 4, 2016
  • Last Reply: Wednesday, October 5, 2016
  • Replies: 2
  • Views: 8542