Parameterize a Web Service Object


#23

To reply to IBUS guy which is hiding behind some noreply adress…
this is my third try to use katalon in my project in last six months. And YES I DID read the docs. And tried everything, and NO, it is NOT easy like in postman.
If you do not want to help, stop mocking me. And YES, documentation SUCKS!


#24

have you searched the forum too? you may find some answers …
amazing, katalon way is ${variable}.or … is the groovy way?

you have exactly one post above you started the new one an example where i show what the previous OP done wrong. did you read it?


#25

Obviously I am not alone, and there is no example on how to do this…
My profile has two variables: host (set as string to host01) and port (set as string to 9876)… that’s all…
i tried REST API URL this ways:

  1. https://${host}:${port}/rest/v1.0/administration/clusters
  2. https://${GlobalVariable.host}:${GlobalVariable.port}/rest/v1.0/administration/clusters
  3. … and everything else that came to my mind in last three installations of katalon.

And it throws errors when called.
I am pretty frustrated, as this should be easy, and I have no idea what I am doing wrong.

As I canot put more that three replies (what a retarded rule), I have to edit previous reply and hope that someone see this:
In profile, I set global variables g_bc and g_port.
Then click send request.
Error is:
Cannot send the test request.
Reason:
For input string: “${g_port}”.
java.net.MalformedURLException: For input string: “${g_port}”
at com.kms.katalon.core.webservice.common.RestfulClient.sendRequest(RestfulClient.java:74)
at com.kms.katalon.core.webservice.common.RestfulClient.send(RestfulClient.java:59)
at com.kms.katalon.controller.WebServiceController.sendRequest(WebServiceController.java:121)
at com.kms.katalon.composer.webservice.parts.RestServicePart$6.run(RestServicePart.java:187)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:119)
Caused by: java.lang.NumberFormatException: For input string: “${g_port}”
… 5 more

If I put port by number and hostname in URL, everything works. But using ${var} is not working.

Well it finally worked, and I have no idea why it was not working before.
I used again URL format I used in method 2: ${GlobalVariable.var} format, and now it works. This is really strange behavior.


#26

what errors did you get? did you set the appropiate headers in the request objects? or do you expect katalon to do all the ‘underhood magic’ for you?


#27

I’m having a related issue, attempting to authenticate to my API via parameters/variables

A GET request:

${url}/authenticate?username=${username}&password=${password}

${url} and ${username} and ${password} are all variables of type String, the default values of which are all seemingly correct.

My API returns:
{
“data”:null,
“message”:“Required String parameter ‘password’ is not present”,
“ok”:false
}
Which I find confusing. Any hints?

The event log says this:

15:22:52.219 [ModalContext] INFO com.kms.katalon.core.webservice.common.HarLogger - HAR: C:\Users\awedd\AppData\Local\Temp\3\har8268017398050496001\requests\ModalContext\60.har

Thu Sep 12 15:22:52 AEST 2019
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:673)
at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
at sun.net.www.protocol.https.HttpsClient.(HttpsClient.java:264)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1199)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1050)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1334)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1309)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:259)
at com.kms.katalon.application.utils.ServerAPICommunicationUtil.sendAndReceiveData(ServerAPICommunicationUtil.java:231)
at com.kms.katalon.application.utils.ServerAPICommunicationUtil.invoke(ServerAPICommunicationUtil.java:123)
at com.kms.katalon.application.utils.ServerAPICommunicationUtil.post(ServerAPICommunicationUtil.java:52)
at com.kms.katalon.tracking.service.TrackingApiService.post(TrackingApiService.java:24)
at com.kms.katalon.tracking.service.TrackingService.sendEventPayload(TrackingService.java:38)
at com.kms.katalon.tracking.service.TrackingService.lambda$0(TrackingService.java:24)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)


#28

are the variables global (defined in profile) or local (declared in the request object)?


#29

@Ibus I believe I have tried both methods to no avail


#30

@adrian.wedd ok, let’s take it step by step.
we are going to use a free test api:
https://reqres.in/

So, kindly reproduce exactly my setup, see the pics: make an request object, set the headers, set the local variables and press the green ‘play’ button. you should get the same response:

Once you confirm is working for you too, we move forward. Otherwise, you did something wrong … or you have connectivity issues.

** note also my katalon version, i am using 6.1.2. although not very important,check yours too to be sure we are almost on the same page.
some versions were known to be buggy


#31

@Ibus Thanks.

I’m running 6.3.3 and I suspect I have a connectivity issue:

I’ll look into that. Interestingly 6.3.3 seems to think I had an illegal character in my url. Presumably “$”?


#32

switch to the ‘Variables Editor’ tab an post a complete screenshot. you may have a mistyping somewhere.


#33

Well spotted @Ibus.

'api/users\r\n'

Presumably my issue (aside from \r\n above) indeed looks to be connectivity. I’ll look at the firewall issue and get back to you tomorrow. Thanks for your hand-holding :slight_smile:


#34

it’s ok, happened to me also … the implementation of the variables tab is not the best, if you press enter after you paste a string such issue may occur.
once you figure out what is wrong with your networking we move forward to use globals