Update to HTTP Header need to be done explicitily

Hello,

I have a web service test object created in Katalon to hit on a REST API.
My REST API have a Basic authentication mechanism. i.e a simple username / password credentials.

I can set this in the Authorization tab of test object , selecting Type as Basic and providing Username and Password.
But I need to click on the “Update to HTTP Header” button manually to update the Authorization header based on credentials. Only then the request will be authenticated.

Can we add this HTTP header during run time automatically, can katalon generates the header and it add during run time ?
So this ‘Update to HTTP header’ button and manual work is not required.

Because of this reason, I can not parameterize Username and Password field
if i try to parameterize userName and password with global variables and pass ${userName} and ${userPassword} as values to this field , these values will not get replaced before the run time and updating HTTP header adds wrong value.
At run time too it wont get added automatically.
Other tool like Postman adds the authentication header automatically based on the basic auth credentials

Can Katalon do that ?

Thanks & Warm Regards
Musaffir

I have the same question, anyone ?

Please try this solution and check if it works:

import static org.assertj.core.api.Assertions.*

import com.kms.katalon.core.testobject.ConditionType as ConditionType
import com.kms.katalon.core.testobject.ObjectRepository as ObjectRepository
import com.kms.katalon.core.testobject.RequestObject as RequestObject
import com.kms.katalon.core.testobject.ResponseObject
import com.kms.katalon.core.testobject.TestObjectProperty as TestObjectProperty
import com.kms.katalon.core.util.internal.Base64 as Base64
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS

// Pass Username an Password details here instead of in Web Service Request Object > Authorization Type tab
String encodedToken = Base64.basicEncode(“username”, “password”)

RequestObject request = ObjectRepository.findTestObject(‘Your-Web-Service-Request-Object-Repository-Path’)

ArrayList<TestObjectProperty> httpHeader = new ArrayList<TestObjectProperty>()

httpHeader.add(new TestObjectProperty(‘Authorization’, ConditionType.EQUALS, 'Basic ’ + encodedToken))
httpHeader.add(new TestObjectProperty(‘Content-Type’, ConditionType.EQUALS, ‘application/json’))

request.setHttpHeaderProperties(httpHeader)

ResponseObject response = WS.sendRequestAndVerify(request)
assert WS.verifyResponseStatusCode(response, 200)