Colle
Colle

Reputation: 154

Set parameters of GET request with groovy

I want to provide parameters for a GET request/ API call to the AYLIEN text analytics API. I can set the headers for the key and ID as authorization and the call itself works (my usage statistics of the API increase after running the code), but I don't know how to provide the text to analyze as a parameter.

def customScript(){

   def connection = new 
   URL("https://api.aylien.com/api/v1/sentiment").openConnection() as 
   HttpURLConnection
   connection.requestMethod = 'GET'

   // set headers
   connection.setRequestProperty('X-AYLIEN-TextAPI-Application-Key','//mykey')
   connection.setRequestProperty('X-AYLIEN-TextAPI-Application-ID', '//myid')                                                                   

   // get the response code - automatically sends the request
   println connection.responseCode  + ": " + connection.inputStream.text

}

Upvotes: 2

Views: 2390

Answers (1)

Gal Naor
Gal Naor

Reputation: 2397

In a GET request, the parameters are sent as part of the URL. For example, if you want to add the parameter id=23, you can change the code to:

def connection = new 
 URL("https://api.aylien.com/api/v1/sentiment?id=23").openConnection() as 
 HttpURLConnection

Upvotes: 1

Related Questions