Getting 400 Bad Request if using variables, but fine with hard coded values

I m able to PUT the HTTP request when i m using had coded values.

But getting 400 Bad request if i m using variable to replace the hard coded value with dynamic value.

Note : For the bad request we are getting below error at the backend

org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value

Hi there,

Thank you very much for your topic. Please note that it may take a little while before a member of our community or from Katalon team responds to you.

Thanks!

Hi @syerra.sunil,

Welcome to our community. I have found this guide doc on your issue: https://docs.katalon.com/katalon-studio/data-driven-testing/data-driven-testing-with-restful-web-service-requests#create-web-service-request-objects-with-variables. Please take a look

Hi there @syerra.sunil, :wave:

Welcome to our forum.

Please take a look at the documentation that Elly proposed.

If the issue persists, then please feel free to seek out support in our Ask Katalon Anything thread below :point_down:

hi @syerra.sunil

the backend already told you what is wrong: “illegal unquoted character (CTRL-CHAR, code 10)”. code 10 is a line feed. so the value katalon put into the body has a newline inside it, the hard coded one does not.

usual sources: the default value in the variables tab was pasted with a trailing enter, the value comes from an excel or csv cell with a line break, or it was built with a groovy triple quote string. quick check, in the verification tab of the request:

println request.getBodyContent().getText().inspect()

inspect() shows the \n explicitly. then fix it at the source, or strip it when you pass the variable, e.g. WS.sendRequest(findTestObject('API/PutThing', [id: myId.trim()])). if the value legitimately has line breaks (an address, a note), the json needs it escaped as \n, so pass it through JsonOutput.toJson(value) and drop the quotes around ${var} in the body.