This is a companion discussion topic for the original entry at https://docs.katalon.com/katalon-studio/docs/web-services-builder.html
This is a companion discussion topic for the original entry at https://docs.katalon.com/katalon-studio/docs/web-services-builder.html
Thank you, I am new to Katalon and scripting. This is working good for me so far. I have one problem though. I am using a data file and it is not applying the Restparameters as expected. Could you please advise? Thank you
import com.kms.katalon.core.testobject.ConditionType as ConditionType
import com.kms.katalon.core.testobject.RestRequestObjectBuilder
import com.kms.katalon.core.testobject.TestObjectProperty as TestObjectProperty
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
//Create a new GET object using builderâ
for (def row=1; row<=findTestData(âGETRequestBuilderâ).getRowNumbers(); row++) {
def builder = new RestRequestObjectBuilder()
def requestObject = builder
.withRestRequestMethod(âGETâ)
.withRestUrl(â${GlobalVariable.RestURL}â+ findTestData(âGETRequestBuilderâ).getValue(âEndPointâ, row))
.withRestParameters([
new TestObjectProperty(âPageNumberâ, ConditionType.EQUALS, findTestData(âGETRequestBuilderâ).getValue(âPageNumberâ, row)),
new TestObjectProperty(âPageSizeâ, ConditionType.EQUALS, findTestData(âGETRequestBuilderâ).getValue(âPageSizeâ, row)),
])
.withHttpHeaders([
new TestObjectProperty(âContent-Typeâ, ConditionType.EQUALS, âapplication/jsonâ),
new TestObjectProperty(âAuthorizationâ, ConditionType.EQUALS, GlobalVariable.token)
])
.build()
//âSend a requestâ
def response = WS.sendRequest(requestObject)
//Verify status code
WS.verifyResponseStatusCode(response, 200)
//Write response to the Console
KeywordUtil.logInfo(response.responseBodyContent)
}
âlogâ : {
âversionâ : â1.2â,
âpagesâ : ,
âentriesâ : [ {
âstartedDateTimeâ : â2020-11-13T14:15:42.945Zâ,
ârequestâ : {
âmethodâ : âGETâ,
âurlâ : âhttps://portal.xxxxx.xxxx.com/backend/api/v2018-07-17/antenna-packagesâ,
âhttpVersionâ : ââ,
âcookiesâ : ,
âheadersâ : [ {
ânameâ : âContent-Typeâ,
âvalueâ : âapplication/jsonâ
Data files looks as follows:

Hi @santie.laing,
Thank you for your report. We will fix this in upcoming releases.
Thank you @huynguyen
Is there another way to get the same result in the meantime?
Regards
Hi @santie.laing,
As a workaround, you can append the parameters directly into your URL.
Hi @huynguyen. That is what I did in the end. It works fine for what I need it for. Thank you for your reply. 
Good day,
Would you mind to give me advice please?
I am using a global variable in the rest body, but I am doing something wrong or itâs not escaping as expected. I am referring to - String body = â{ânameâ:"${GlobalVariable.newCompanyName}"}â Iâve tried to use single quotes around the variable as well.
It works fine if I use a hard coded value in double quotes in stead of the variable. e.g. {ânameâ:âSantie14â}.
Thank you! 
//Set date variable
def todaysDate = new Date()
def todaysDateFormatted = todaysDate.format(âddMMyy-HH:mm:ss.SSSâ)
//Set new company name as âNew Company + todayâs date and time)
value0 = âAuto New Companyâ + todaysDateFormatted
println(ââŚNew Company Name is:â + value0)
//Store new company name in Global Variable
GlobalVariable.newCompanyName = value0
println(GlobalVariable.newCompanyName)
String body = '{ânameâ:"${GlobalVariable.newCompanyName}"}'
println(body)
//Create a new POST object, using builder to create a new company with this unique name
def builder = new RestRequestObjectBuilder()
def requestObject = builder
.withRestRequestMethod(âPOSTâ)
.withRestUrl("${GlobalVariable.RestURL}"+ âcompaniesâ)
.withHttpHeaders([
new TestObjectProperty(âContent-Typeâ, ConditionType.EQUALS, âapplication/jsonâ),
new TestObjectProperty(âAuthorizationâ, ConditionType.EQUALS, GlobalVariable.token)
])
.withTextBodyContent(body)
.build()
//âSend the requestâ
def response = WS.sendRequest(requestObject)
//Verify status code
WS.verifyResponseStatusCode(response, 200)
//Parse the response
def jsonSlurper = new JsonSlurper()
def result = jsonSlurper.parseText(response.getResponseBodyContent())
def valueId = result.id
def valueName = result.name
println(ââŚId extracted is : â +valueId)
println(ââŚName extracted is : â +valueName)
Hi @santie.laing,
Please try `String body = â{ânameâ:â${GlobalVariable.newCompanyName}"}"
Hi @huynguyen
Thank you for your prompt reply. I adjusted it a bit and it worked for me. Tx again. ![]()
String body = â{"name":"${GlobalVariable.newCompanyName}"}â
Kind regards
@santie.laing,
Glad to hear that. I should have said that you ought to put some escape characters before using my answer, but you did it without further help. 