How to use setBodyContent(HttpBodyContent)

I have been trying to update our test management API once the Katalon test has completed.

We are using Adaptavist Test Managaement in JIRA. I am not trying to update the Katalon JIRA add-on by the way.

The API call, for Adaptavist, needs to be a POST and have a body message of items like the example {“projectKey”: “FVS”, “testCaseKey”: “FVS-T1”, “status”: “Pass”, “environment”: “DEV”}
I would eventually replace these items with the Katalon test variables as appropriate.

I have created a Service Call in the Object Repository which deals with auth settings, this works fine if I test the request in the editor with these sample values.

When I come to add the script in the Test Case itself I am struggling to get it work, let alone replace the variables with the actual values.

I current have this :

//run testWebUI.openBrowser('')WebUI.navigateToUrl(GlobalVariable.MainURL)WebUI.verifyElementClickable(findTestObject('img_img-responsive_1'))WebUI.verifyElementClickable(findTestObject('img_img-responsive_2'))WebUI.verifyElementClickable(findTestObject('img_img-responsive_3'))WebUI.closeBrowser()//update JIRARequestObject getJIRAUpdateObject = (RequestObject)findTestObject('Web Service Calls/Update JIRA')String vsRequestBody = '{"projectKey": "FVS",  "testCaseKey": "FVS-T1",  "status": "Pass", "environment": "DEV"}';body = getJIRAUpdateObject.setHttpBody(vsRequestBody)WS.sendRequest(getJIRAUpdateObject)

I also have the following additional imports

import com.kms.katalon.core.testobject.ResponseObjectimport com.kms.katalon.core.testobject.RequestObject

Now in the script editor I am told that setHttpBody is now depreciated in Katalon version 5.4+ (I am using 5.4.1) and I should use setBodyContent(HttpBodyContent) instead, but when I look at the API documentation for this, I cannot work out the syntax of how I am supposed to use this instead.

Does anyone know how I should change the code, or have examples of how I need to change the above code to use this new method ??

Any help is much appreciated.


Hi Darren,

In your case, the body content is text body then the suitable implementation should be:

import com.kms.katalon.core.testobject.impl.HttpTextBodyContent //for text in bodyimport com.kms.katalon.core.testobject.impl.HttpFileBodyContent //for file in bodyimport com.kms.katalon.core.testobject.impl.HttpFormDataBodyContent //for form data bodyimport com.kms.katalon.core.testobject.impl.HttpUrlEncodedBodyContent //for URL encoded text bodysetBodyContent(new HttpTextBodyContent(your_text))

We also built a RequestObjectBuilder to help users can create dynamic RequestObject easier.

Btw, there was a mismatched in building API docs process then the document of all HttpBodyContent implementations are missing. We will update soon.

Sorry for your inconvenience.


That worked :slight_smile:

I will have a look at the RequestObjectBuilder too.

Many Thanks

We’ve updated our API docs for HttpBodyContent implementations, you can find it here: Thanks to all for your information.

Thank you Duyluong

I’m getting this error when I use HttpFileBodyContent
groovy.lang.MissingPropertyException: No such property: text for class: com.kms.katalon.core.testobject.impl.HttpFileBodyContent

I’ve created a Keyword
def Uplaod_Version(String uploadLink) {
RequestObject ro= new RequestObject()
HttpFileBodyContent filePath= new HttpFileBodyContent(“C:\Users\hina.amir\Desktop\test.dxf”)
ro.setBodyContent(new HttpFileBodyContent(“C:\Users\hina.amir\Desktop\test.dxf”))
//Send request
ResponseObject responseUpload = WS.sendRequest(ro)