How can I set value for REST API Query Parameter in test case?

I’m new to Katalon and trying to understand how can I pass the query parameter for Rest request from the test case?

e.g. a simple POST Rest request to create an item
Post : http://${IP}/items/name=test

I want to pass the value for “name” parameter from the test case.

The URL seems not in the correct format, so I am not sure what kind of parameter you want to use.
If it is Query Parameters, you can set the value as shown in the following screenshot

I have setup request parameters as in the snapshot.

image

Then in Test case I have following code where I am setting value of Global variable

RequestObject request= findTestObject(‘create_folder’, [(‘IP_Add’) : GlobalVariable.Server])

GlobalVariable.PrjName=“prjName”

ArrayList HTTPHeader = new ArrayList()

HTTPHeader.add(new TestObjectProperty(‘name’, ConditionType.EQUALS,GlobalVariable.PrjName))

request.setHttpHeaderProperties(HTTPHeader)

response= WS.sendRequest(request)
if (response.getStatusCode()==201)
{
KeywordUtil.markPassed("request successful item deleted: " + + response.getStatusCode()+ response.getResponseBodyContent())
}
else
{
KeywordUtil.markFailed('request unsuccessful: ’ + response.getResponseBodyContent())
}

But the JSON response shows that the item name is set to “name”: “${name}”, instead of “name”: “prjName”, :confused:

I was missing name global variable while initializing request object. Also setting Global Variable before request object initialization Fixed it …

GlobalVariable.PrjName = “prjName”

RequestObject request= findTestObject(‘create_folder’, [(‘IP_Add’) : GlobalVariable.Server, (‘name’) : GlobalVariable.PrjName])

ArrayList HTTPHeader = new ArrayList()
HTTPHeader.add(new TestObjectProperty(‘name’, ConditionType.EQUALS,GlobalVariable.PrjName))

request.setHttpHeaderProperties(HTTPHeader)

response= WS.sendRequest(request)
if (response.getStatusCode()==201)
{
KeywordUtil.markPassed("request successful item deleted: " + + response.getStatusCode()+ response.getResponseBodyContent())
}
else
{
KeywordUtil.markFailed('request unsuccessful: ’ + response.getResponseBodyContent())
}

:partying_face:

2 Likes