Rest request oAuth2 token POST

I want to utilize oAuth2 for a token POST request. I do not see any native support for this authorization format. I think a custom keyword may be the way but I need advice. I have created in the Object Repository a Token Post request, and it works, when I manually add an Authorization in HTTP Headers ( contains realm, basic logon parameters, timestamp and nonce…) and it returns the Token. My question is, How can I execute a groovy script within a custom keyword to generate the Authorization values and post them to the Authorization field in the HTTP Headers of my Object (Token_oAuth in the Repository ) or could I run a script inline of the test case to generate the Authorization string values and then add them to the Token_oAuth Object as it is called perhaps as a parameter ?


Any advice is appreciated,


Thank you for your response, however The name of my Web Service request has changed to POST because I recreated each portion and verified their functionality prior to responding . The web Service does function as expected when configured with hard coded values (set in the web service) my issue is setting the value of the HTTP Headers ‘Authorization’ from the script within the test case.

So using the example above the line “header.setValue(‘Basic realm=MyPage.NET&grant_type=password&’)” is failing to set the value. I also note that failure does not throw an error or exception. I have tried passing both variables with assigned strings, and as shown a hard coded string, with no change. The value is not assigned to the Authorization header in the Web service request.

The reason of your failure is

responseData = WS.sendRequest(findTestObject(‘POST’))

You need to use as

responseData = WS.sendRequest(tokenOAuth)

I have tried both options, but with no success. Neither adding a string value to the preexisting HTTP header ‘Authorization’ or adding the Header value ‘Authorization’ + string value worked for me. I am using Katalon Studio Version: 4.4.0 Build: 1.

When I run the test I am returned a 400 error, and when i open the WebServiceRequest I see the property has not value.

I am using this script. the Web service request is called POST (its an oAuth2 POST request, I am wanting to add a string value to the HTTP Header, ‘Authorization’)

RequestObject tokenOAuth = findTestObject(‘POST’)

for (TestObjectProperty header : tokenOAuth.getHttpHeaderProperties()) {
if (header.getName().equals(‘Authorization’)) {
header.setValue(‘Basic realm=MyPage.NET&grant_type=password&’)


responseData = WS.sendRequest(findTestObject(‘POST’))
responseCode = responseData.getStatusCode()
println('Response Code: ’ + responseCode)

responseText = responseData.getResponseText()
println('Response body: ’ + responseText)

It does appear the even though no error is thrown, I cannot add a value to the HTTP Headers ‘Authorization’ or add a header as in either of your examples. Am I missing something environmental?



Hi Mark,

You could

run a script inline of the test case to generate the Authorization string values and then add them to the Token_oAuth Object as it is called perhaps as a parameter


// need to import com.kms.katalon.core.testobject.RequestObject// need to import com.kms.katalon.core.testobject.TestObjectPropertyRequestObject tokenOAuth = findTestObject('Your Token_oAuth ID')// Option 1: tokenOAuth already has Authorization header valuefor (TestObjectProperty header : tokenOAuth.getHttpHeaderProperties()) {    if (header.getName().equals('Authorization')) {        header.setValue('Your new token value')        break    }}// Option 2: tokenOAuth has none Authorization header value// need to import com.kms.katalon.core.testobject.ConditionTypetokenOAuth.getHttpHeaderProperties().add(new TestObjectProperty('Authorization', ConditionType.EQUALS, 'Your token value'))

You can refer to the test case: Test Cases/Web API/JIRA REST API/TC02_CreateUser_AddUserDataSuccessfully in the following project to resolve your issue:

The given solution in that test case is to add custom fields into HTTP headers:

requestUser.getHttpHeaderProperties().add(CustomKeywords.‘com.example.WebApiCustomKeywords.createBasicAuthProperty’(P_UserAdmin, P_PassAdmin))

Noticed last updated is nearly a year ago. Has anyone figured out a way to do this?

I started using katalon studio and automated many rest api’s using normal authorization. But recently they moved to Aouth2.0 and i need to migrate all these to Aouth2.0.
i tested same in postman which is working fine. But i would like to use Katalon studio for Aouth2. Can anyone help me how to use it in katalon studio.
any help is appreciated.


1 Like

I have the same problem, I would need to use Katalon with Aouth 2.0. Do you plan to be included in any version?

If so, on what date will it be available?

1 Like

Dear guys,

We have published a Beta release with OAuth2 feature for API Testing: BETA release for OAuth2 feature of API Testing

Please help try it out and feel free to give us your feedback.

Best regards,

1 Like

Hi Dung_Ngo, Greetings.

Thanks for oauth2 implementation in katalon beta version.
I tested this feature and sometimes the genarated token giving 500 error. The token is working inconsistently with 500 error.
Not sure what is the issue.

But you guys did a great job. And when this will be available in current version?

Thanks in advance.


Dear @anuradha_yendluri,

Thanks for your feedback. The feature should be available by March at the latest.
By the way, can you help provide us more details about the 500 issue you encountered?

Best regards,

Hi Dung_Ngo, Greetings.

Thanks for the quick reply. Happy for the oauth2 feature and great it is coming in March.
Regarding 500 error, i checked it multiple times and understood it is a internal server issue.
Now i am using this feature in beta version to get access token which is working perfectly fine.

Now i want to automate this access token generation process using scripts/code/custom keyword, instead of filling the data under authorization tab manually.

Can you help me how to automate this process.

Note: I want to fill the data as shown in the pics below and with out using Request Token button, it is possible to access this information by calling object repository and generate the url and hit in the browser and login , then get the code and pass it to token url which will give access token.

This is what i am thinking .
Please suggest.

Thanks in advance.


Hi Dung_Ngo, Greetings.

I worked on Oauth2 and able to automate without using beta version.
If any one need the code , i will share it.

1 Like

Can you please share the code ?
Appreciate your help.

I would also be very interested in looking at your Oauth2 automation example.
Thanks in advance,

Hi @anuradha_yendluri,

Can you please share the code ?

Thanks in advance

Have you tried to set your access token to be a global variable. I am trying to do something like this in the HTTP Header window/editor

Authorization Bearer $(accessToken)

The accessToken is a global and passed from command line.

Appreciate any help.


Hi @anuradha_yendluri,
Can u please share the code with me also…

Thanks in advance…

Hi Anaradha, can you please share the code, thanks in advance