Parameterize a Web Service object

Hello,

I’m working on the automatisation API. My version of katalon is 5.4.1
I tried to vary the body of my post with the explanation of the page if against :
https://docs.katalon.com/display/KD/Parameterize+a+Web+Service+object
In my script i define :

def a = WS.sendRequest(findTestObject(‘New_Request_Auth’, [(email) : ‘sgappfr2@vpmel.fr’, (password) : ‘azerty!!’]))
In the HTTP body:

however, the WS responds with an error, as if the parameters were not correctly sent. With the data without variables in the body the WS responds correctly.
Help please.

image.png

Hi sgazeaux,
Maybe your script’s syntax is incorrect.
Please try:

def a = WS.sendRequest(findTestObject('New_Request_Auth', ['email' : 'sgappfr2@vpmel.fr', 'password' : 'azerty!!']))

instead of

def a = WS.sendRequest(findTestObject('New_Request_Auth', [(email) : 'sgappfr2@vpmel.fr', (password) : 'azerty!!']))

Thanks.

Hello duyluong,

Thanks for your answer, but it is the same error with your syntax. This syntax is generated automatically in the script when I insert object parameters in The objectPost

I don’t understand what could be the problem.

Thanks for you help

Test Object Input.jpg

Hi All,

Can any one got the solution for the issue reported by sgazeaux

Please let us know one we solved above issue. Currently we too facing the same issue

Thanks & Regards

Try putting quotes around your parameters in your JSON i.e. “${email}” and “${password}” the parameters work like macro-substitution. You still need the quotes. (I think)

Hi John,

Thanks for acknowledged, but still its not solving the problem. If you have any idea how to resolve, please help me out here

Calling statement:

def responseRetriveContactDetails = WS.sendRequest(findTestObject(‘RetrivePersonDetails’, [(‘contactURN’) : customerURN]))

In SoapUI request:

I have used in below format

v11:personIdentity${contactURN}</v11:personIdentity>

During execution, contactURN value still not passing.

Hello John Paul,

Effectively, when I’m putting quotes in the parameters, i’ts ok ! That is the solution.
Thanks a lot John !

Best Regard.

Hi Sgazeaux,

Can you help me on how to store specific attribute in variable from JSON

def response = WS.sendRequest(findTestObject(‘REST_CommentDetails’))

def responseCode = response.getStatusCode()

println('Response Code: ’ + responseCode)

// respone body

def responseText = response.getResponseText()

println('Response body: ’ + responseText)

def jsonObject = new groovy.json.JsonSlurper().parseText(responseText)

Getting error on below line
println(jsonObject.[0].name)

If you get a error on print line, check your path on http://jsonpath.com/ website
I’m not sure that the [0] position is necessary, make sure that is ok.

Hi Sgazeaux,

Thanks for great help!!

Can you please clarify me on below query at last

Code:

String Email= jsonObject.email[0]+“Lucky”

println(Email)

// Try to post updated email and view response

def responsePost = WS.sendRequest(findTestObject(‘PostUpdatedEmail’, [‘email’ : Email]))

def responseTextPost = responsePost.getResponseText()

println('Response body: ’ + responseTextPost)

JSON:

{

"postId": 2,

"id": 6,

"name": "et fugit eligendi deleniti quidem qui sint nihil autem",

"email": "${email}",

"body": "doloribus at sed quis culpa deserunt consectetur qui praesentium\\naccusamus fugiat dicta\\nvoluptatem rerum ut voluptate autem\\nvoluptatem repellendus aspernatur dolorem in"

}

But here when I trigger my code, am unable to pass Email to email attribute mentioned JSON.

It would great helpful us if you provide solution

Hi Kavia. When you are loading the test object, try: findTestObject(‘PostUpdatedEmail’, [(email) : Email]) instead of findTestObject(‘PostUpdatedEmail’, [‘email’ : Email])

Hi John,

// Try to post updated email and view response

def responsePost = WS.sendRequest(findTestObject(‘PostUpdatedEmail’, [(email) : Email]))

def responseTextPost = responsePost.getResponseText()

println('Response body: ’ + responseTextPost)

Code:

When I run getting below error message

// Try to post updated email and view response

def responsePost = WS.sendRequest(findTestObject(‘PostUpdatedEmail’, [(email) : Email]))

def responseTextPost = responsePost.getResponseText()

println('Response body: ’ + responseTextPost)

JSON:

{

"postId": 2,

"id": 6,

"name": "et fugit eligendi deleniti quidem qui sint nihil autem",

"email": "${email}",

"body": "doloribus at sed quis culpa deserunt consectetur qui praesentium\\naccusamus fugiat dicta\\nvoluptatem rerum ut voluptate autem\\nvoluptatem repellendus aspernatur dolorem in"

}

Getting below error message

[ERROR] - Test Cases/DemoRestAutomation FAILED because (of) Variable ‘email’ is not defined for test case.

If I define Variable eamil inside test case as well, actual value not passing

Variables are case sensitive. While in your test object you are passing the variable EMail, your error indicates the variable _email. _Could you be dealing with two different variables here?

Hi John,

Still we are facing same problem, After changing variable name as well

Code:

/ Try to post updated email and view response

def responsePost = WS.sendRequest(findTestObject(‘PostUpdatedEmail’, [(Email) : Email]))

def responseTextPost = responsePost.getResponseText()

println('Response body: ’ + responseTextPost)

JSON:

{

"postId": 2,

"id": 6,

"name": "et fugit eligendi deleniti quidem qui sint nihil autem",

"email": "${Email}",

"body": "doloribus at sed quis culpa deserunt consectetur qui praesentium\\naccusamus fugiat dicta\\nvoluptatem rerum ut voluptate autem\\nvoluptatem repellendus aspernatur dolorem in"

}

Email variable value still not passing

Kavia said:

Hi John,

Still we are facing same problem, After changing variable name as well

Code:

/ Try to post updated email and view response

def responsePost = WS.sendRequest(findTestObject(‘PostUpdatedEmail’, [(Email) : Email]))

def responseTextPost = responsePost.getResponseText()

println('Response body: ’ + responseTextPost)

JSON:

{

"postId": 2,

"id": 6,

"name": "et fugit eligendi deleniti quidem qui sint nihil autem",

"email": "${Email}",

"body": "doloribus at sed quis culpa deserunt consectetur qui praesentium\\naccusamus fugiat dicta\\nvoluptatem rerum ut voluptate autem\\nvoluptatem repellendus aspernatur dolorem in"

}

Email variable value still not passing

Can any body have the answer for Query?

Is there already solution for this?
Im having the same problem