How to Create and pass Variable for Bearer Token?

I have a Bearer Token, and created Variable , But When i use the variable in another Test case i got Unauthorized Error.

Below Pic Shows how i creates the variable for Token.

Please help Resolving the issue.

Error ScreenShot

Could You please help me on above query ?

Looks like you have a typo in the variable in first screenshot (‘sessinKey’). You then use ‘sessionKey’ in the second screenshot. Hope that helps :slight_smile:

Issue 1 : i corrected the Typo, and passed the varibable but it still Throws Unauthorized Error.

Hi @roshinakt,
Can you show me the Variables tab of the request that needs authorization?

Here is my Response and variable i created

2,This pic shows the variable i have created in Authrization has been passed Here.

Please let me know, Is there something i missed, Also i need to pass this Authorization in all Test cases.
So please help me to resolve this issue.

Hi @roshinakt,
By using different test cases, do you mean that you use one request object to get the session key and other request objects that utilize this session key?

Yes ! Without this Authorization i cannot Proceed other Test cases, So i need this Auth to Pass in all Requests Test cases

Hi @roshinakt,
You mean that after getting the session key, you will manually enter it to other request objects?

I guess you can pick up a value out of a Response object and pass the value to next Request, by something like this.

def request1 = findTestObject('RequestObject1')
def response = WS.sendRequest(request1)
def body = response.getResponseBodyContent()
def slurper = new JsonSlurper()
def jsonBody =slurper.parse(text)
def sk =
def request2 = findTestObject('RequestObject2', [('Authorization') : "Bearer ${sk}"])

Sorry I haven’t tried yet.

Yes, I don’t want to Pass the Session Key Hard-coded, Rather i would like to pass the session Key as Variable.

You can use a global variable to pass a certain variable across testcases.
Search the forum, there are plenty topics on this matter

1 Like

I have Create a Global Variable using Default Profile View and pass the variable in Appropriate Request , But i got Unauthorized Error again.

@bionel Thank you so Much Its working Now, after Creating a Global Variable. You can Ignore my Previous message.

@huynguyen Thank You it’s working now, after Creating a Global Variable using Default Profile View.

@huynguyen @bionel i have another Query,

I have generated Transaction id using POST Request , So This Object is Utilized by Other Object Request(PUT), and i want to pass the same Transaction ID in PUT Command URL, So please advise how to use the ID using variable.

So please advise ,How to Create Variable for this Transaction ID Field in Response and parameterized.

ScreenShot of both Screens.

Please advise on above query ?

basically you have to do it exactly the same as you did for the token.
grab the transactionId from the POST request response, save it to a GlobalVariable, use the Global in the PUT request

1 Like

Thank You ! Working

1 Like

@bionel @huynguyen IN POST Request- I generate Transaction ID and i have created Global Variable, This ID is Unique

The API will Create a New Transaction-ID Every-time i Run, While Automating it will the take value of the Existing Transaction ID not the New one. Since i have use the same Transaction ID for PUT Request as well.

If i manually Change Transaction ID it will Work , But in Automation It fails, So please advise how to handle it.