Passing values into API calls


I need to be able to pass values between API calls.

For example, if I have 2 API calls, getToken and getUsers and from getToken I obtain token that I need to pass to getUsers call as a part of HTTP Header.


Something like "Authorization": "Bearer ${GlobalVariable.gToken}"




  • Hi Rasko,
    first of all, you have to save your token from first API call into a variable.
    Then, please try following code:

    TestObjectProperty prop = new TestObjectProperty()
    prop.setValue("Bearer " + yourToken)


    List<TestObjectProperty> headers = new ArrayList<>()


    RequestObject reqObj = new RequestObject()

    def getResponse = WSBuildInKeywords.sendRequest(reqObj)
  • Hopefully, going thru this sample test case you will find the answer

    import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
    import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
    import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
    import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
    import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
    import com.kms.katalon.core.checkpoint.CheckpointFactory as CheckpointFactory
    import as MobileBuiltInKeywords
    import as Mobile
    import com.kms.katalon.core.model.FailureHandling as FailureHandling
    import com.kms.katalon.core.testcase.TestCase as TestCase
    import com.kms.katalon.core.testcase.TestCaseFactory as TestCaseFactory
    import com.kms.katalon.core.testdata.TestData as TestData
    import com.kms.katalon.core.testdata.TestDataFactory as TestDataFactory
    import com.kms.katalon.core.testobject.ConditionType
    import com.kms.katalon.core.testobject.ObjectRepository as ObjectRepository
    import com.kms.katalon.core.testobject.RequestObject
    import com.kms.katalon.core.testobject.ResponseObject
    import com.kms.katalon.core.testobject.TestObject as TestObject
    import com.kms.katalon.core.testobject.TestObjectProperty
    import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WSBuiltInKeywords
    import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
    import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUiBuiltInKeywords
    import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
    import internal.GlobalVariable as GlobalVariable

    // load test request object which will do the login step and retrieve the token for later usages
    RequestObject getTokenTestObject = findTestObject('Auth/Get User Token')

    // current value: { username: '_username_', password: '_password_'}
    // suppose that _username_ and _password_ are the invalid values and you want to change on runtime
    body = getTokenTestObject.getHttpBody().replace("_username_", "valid username").replace("_password_", "valid password")
    // You might use Test Case variable or Global variable to store the user credentials

    // update back the HTTP request body

    ResponseObject responseTokenObject = WS.sendRequest(getTokenTestObject)

    // suppose that the responseTokenObject.getResponseText() is { accessToken: "xxx", expiredTime: "yyy" }
    // use groovy.json.JsonSlurper to parse the text into object
    def tokenObject = new groovy.json.JsonSlurper().parseText(responseTokenObject.getResponseText())

    // get the retrieved token
    token = tokenObject.accessToken

    // load test request object which will use token above in Authorization
    RequestObject getUserInfoTestObject = findTestObject('Auth/Get User Info')

    // if getUserInfoTestObject HTTP headers have no Authorization item
    getUserInfoTestObject.getHttpHeaderProperties().add(new TestObjectProperty("Authorization", ConditionType.EQUALS, "Bearer " + token))

    // Otherwise, you need to go through the getUserInfoTestObject.getHttpHeaderProperties() and replace the value of Authorization header
    //for (TestObjectProperty header: getUserInfoTestObject.getHttpHeaderProperties()) {
    // if ("Authorization".equals(header.getName())) {
    // header.setValue("Bearer " + token);
    // break;
    // }


This discussion has been closed.