Thread

Skip Navigation LinksForums > SpiraTest Forums > SpiraTest Issues & Questi... > Sample Code to do post an...

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

Tuesday, October 4, 2016
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
Droid MannDroid Mann
re: Droid Mann on Tuesday, October 4, 2016
Wednesday, October 5, 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????
Droid MannDroid Mann
re: Droid Mann on Tuesday, October 4, 2016
Wednesday, October 5, 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????
Statistics
  • Started: 10/4/2016
  • Last Reply: 10/5/2016
  • Replies: 2
  • Views: 140
Powered by KronoDesk v1.1.0.15 | © Copyright Inflectra Corporation 2011-2016 | Licensed to Inflectra Corporation.