[KShare] How to get the values of the HTTP header and Local Variables of the API requests?

Hi all, :wave:

For May, we are going to focus on API Testing tips, tricks, and tutorials to help you test better with the Katalon Platform. :rocket:

Have you ever encountered difficulties attempting to obtain online service approach suggestions? Like the screenshot below…

If you do, then you should apply the syntax below:

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

RequestObject requestObject = findTestObject('HTML_GetResponse')
ResponseObject response = WS.sendRequest(requestObject)

After fixing the request and response methods, we will address the primary question of API testing, which is: how to obtain the properties of the HTTP header or Local Variables of the API requests.

HTTP Header

In the HTTP Header, we have Content-Type and the API Key. Now, we will get the value of API Key with the scripts below:

RequestObject requestObject_UploadFile = findTestObject('Katalon_API_Demo_Requests/Post_Upload_File')
List headerProperties = requestObject_UploadFile.getHttpHeaderProperties()
def array = []
for(TestObjectProperty i: headerProperties) {
print array[1]

println GlobalVariable.apikey
GlobalVariable.apikey = array[1]
println GlobalVariable.apikey

You can refer to the video below to learn more on how it works:

Please also feel free to refer to the link bebelow for a sample project:



import com.kms.katalon.core.testobject.RequestObject
RequestObject requestObject = findTestObject('Object Repository/Post_Upload_File')
Map<String, Object> variables = requestObject.getVariables()

If you find this article helpful, then don’t forget to leave us a like :+1: or a heart :heart: and share this article with your colleagues and teammates!

To see more KShare articles, simply navigate to the support tag.


Thank you the Product Support team (@support.squad) and Linh Nguyen (@linh.nguyen) for another informative article. We look forward to seeing more API-related articles from you!

Linh Nguyen
Linh Nguyen (@linh.nguyen) - Product Support Manager at Katalon
Linh is the Product Support team Manager at Katalon. She spent many years working as an Automation Testing QA before joining Katalon Product Support as a technical support expert. Based on her experiences, she usually provides consumers with highly applicable solutions. She now manages her team with a user-centric approach to guarantee customers greater success with Katalon Products.