Assign global variable in the HTTP header of a WebService request


Is there a way to call global variables (say from my execution profile) and assign it as part of the HTTP header of a web service request?

I’m using Katalon 5.10.1


I’m also wondering the same thing.
In my case, I get an authentication token from a rest request, then I assign the token to a global variable. I’d like to use that global variable in the headers of other web service objects during run time for authentication. Is there a way to do it?

1 Like

see the doc:

using the variables tab you can declare a variable having the value as the global variable you need, or just call the request object from the testcase passing the desired global as a parameter

Thank you for pointing that out! It did the job

how it works tell me please ?

Hi, here’s how I’ve solved my authentication token drama:

  1. First, I’ve created a global variable of type String, with an empty value. I’ve called it ‘AuthToken’ or whatever.

  2. Then I have a test listener that executes before every test suite and sends a request to the authentication endpoint of my web app. This web service call gets an authentication token in the response body.

  3. In that webservice object that fetches the token, I’ve written a line of code that assigns the content of the response (the auth token itself) to the AuthToken global variable. Here’s how it looks:

     def token = response.getResponseText()
     GlobalVariable.AuthToken = String.format("Bearer %s", token) // note the "Bearer" part
  4. Now that I have the authentication token in my global variable, I can use it in the headers of my other web service calls for authentication.

  5. On your other web service objects, create a new variable and set it to point to your global variable with the token.

  6. Then in the HTTP Header tab, add a new Authorization property and set its value to ${name_of_your_variable}

The last two steps are explained with more details in the “Parameterize a Web Service Object” link somewhere above. There could be an easier way that I’ve missed, but oh well. This works for me :sweat_smile:


can you help me with this, I’m having a hard time following what you stated? This is so much easier in POSTMAN.

I currently have mine working the same as @Mitaka_S but for OAuth. I have a separate GlobalVariable for consumerKey, consumerSecret, accessToken, accessTokenSecret.

Each of those are then consumed by local variables in the variables tab of the Web Service Request object.

Ideally I would prefer to store those 4 keys in a GlobalVariable map and then consume that but the variables tab in Web Service Request just doesn’t like it. When I try and set GlobalVariable.apiAuth[“consumerKey”], it changes it to null. I also tried changing it in the file on disk but it does the same thing.

Can this be done?

When I tried to reproduce your issue, it worked fine. I do not see why you have a problem.

Please take and show us a screenshot of your Web Service Object definition where you wrote GlobalVariable.apiAuth[“consumerKey”].