The correct syntax for receiving requests using rest-client

Now I can make a request as follows:

user = 'xxx' token = 'xxx' survey_id = 'xxx' response = RestClient.get "https://survey.qualtrics.com/WRAPI/ControlPanel/api.php?Request=getLegacyResponseData&User=#{user}&Token=#{token}&Version=2.0&SurveyID=#{survey_id}&Format=XML" 

But there must be a good way to do this. I tried things like:

 response = RestClient.get "https://survey.qualtrics.com/WRAPI/ControlPanel/api.php", :Request => 'getLegacyResponseData', :User => user, :Token => token, :Version => '2.0', :SurveyID => survey_id, :Format => 'XML'</code> 

and their variations (strings instead of characters for keys, including {and}, making lowercase keys, etc.), but none of the combinations that I tried seem to work. What is the correct syntax here?


I tried the first sentence below. This did not work. For the record, this works:

 surveys_from_api = RestClient.get "https://survey.qualtrics.com/WRAPI/ControlPanel/api.php?Request=getSurveys&User=#{user}&Token=#{token}&Version=#{version}&Format=JSON" 

but this is not so:

 surveys_from_api = RestClient.get "https://survey.qualtrics.com/WRAPI/ControlPanel/api.php", :params => {:Request => 'getSurveys', :User => user, :Token => token, :Version => version, :Format => 'JSON'} 

(where I installed version = '2.0').

+4
source share
3 answers

You need to specify query string parameters using the: params symbol. Otherwise, they will be used as headings.

Example with parameters:

 response = RestClient.get "https://survey.qualtrics.com/WRAPI/ControlPanel/api.php", :params => {:Request => 'getLegacyResponseData', :User => user, :Token => token, :Version => '2.0', :SurveyID => survey_id, :Format => 'XML'} 
+11
source

I had the same problem with Rest-Client (1.7.2) I need to put both parameters and HTTP headers.

I solved with this syntax:

 params = {id: id, device: device, status: status} headers = {myheader: "giorgio"} RestClient.put url, params, headers 

I hate RestClient :-)

+3
source

In the rest-client api docs, I see that headers are Hash , and if you want to provide both headers and parameters, then you need to use the key :params inside the headers Hash. eg.

headers = { h1 => v1, h2 => v2, :params => {my params} }

+1
source

All Articles