Parameterize a Web Service Object

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!

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?

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.

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?

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)

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

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

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

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

@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 “$”?

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

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:

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

Can i define the local variable like systemDate in Verifications tab and call it in HTTP json body?

def date = new Date()
sdf = new SimpleDateFormat(“YYYY-MM-dd”)
def systemDate= sdf.format(date)

In Json body:

{

“due_date”:“${systemDate}”

}

Do I define this variable under “Variables” tab to pull in my json body? if so, how do i define this as local variable?
image

Wondering how to use the List variables within the Web Service Request. Do you call it like a string or do you have to write it different within the body?

Is there a way to send a parameter as a boolean and not a string ?
My case : where I type ${urlPassCollecte}/api/user-profil/${adh}?msgInfo=false as the request URL, Katalon generates
“queryString” : [ {
“name” : “msgInfo”,
“value” : “false”
} ]
(with double-quotes around false value), casting i fact the boolean to a string value.
The API under tests expects a boolean (the same QueryString without the double-quotes around false) and therefore answers an error to my request.
Any clue ?
Tanks in advance,

an url in the end is just a string, no matter if some tools are able to split what is after ? as key=val parameters.
looks for me like a bad designed API, it should be able to cast internally false | False | no | No into boolean

What about including a dynamic variable within the URL of the GET? I have tried but it does not work.

Included the variable in the test case: category_id, number, default value 0.

GET URL/product/${category_id}.json

WS.sendRequest(findTestObject(‘API/products’), [(‘category_id’) : categoryID])

It fails on the send request: Reason:
groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords.sendRequest() is applicable for argument types: (com.kms.katalon.core.testobject.RequestObject, java.util.LinkedHashMap) values: [TestObject - ‘Object Repository/API/products’, [category_id:15]]
Possible solutions: sendRequest(com.kms.katalon.core.testobject.RequestObject), sendRequest(com.kms.katalon.core.testobject.RequestObject, com.kms.katalon.core.model.FailureHandling)

Any help?
Thank you!

hello,
anybody knows a way to use a variable of type Map ?
image
I don’t find a correct syntax to get my withPAPG value from my Map variable

I tried ${params[‘withWCSParam’]}, ${params.withWCSParam}, $params.withWCSParam without achieving

it compose this kind of url :

GetGeekData?depositCode=CPE&activityCode=EPF&withPAPG=%5BwithPAPG%3Atrue%2C+w