Satria
Satria

Reputation: 35

Passing variable from response to header in JMETER

First request for the JSON in response body which looks like this:

{"data":{"userId":"USR-0000000000000001","accessToken":"TKN-05TS53MFRVK2QYH2HMLD3J25WMH8IH6E767W","refreshToken":"RTK-88TLRIYE4YVJMWH2H4G0UQK83DVCWODFLX4X","expiresIn":"2018-03-16 20:14:00","tokenType":"bearer"}

I extract the value of the "accessToken" attribute using the "Regular Expression Extractor": regular expression

Then I pass the "Authorization" variable to the header, this step i need to put accesstoken to get information on my profile: enter image description here

But then showing me this response on the results tree enter image description here

and response showing

"{"error":{"errorCode":1001,"errorMessage":"Authentication failed"}}"

What i want is on the next request can sucessfully read the accesstoken. can somebody help if theres something wrong on this?

Thanks

Upvotes: 3

Views: 5547

Answers (3)

Ori Marko
Ori Marko

Reputation: 58774

You should put in the Regular expression extractor the name of the created variable.

Replace in regular expression from Authorization to accessToken because it is the name of the variable created that you are using

Upvotes: 0

Dmitri T
Dmitri T

Reputation: 168002

  1. You need to change header value to Bearer ${Authorization}, as per RFC 6750 it should start with Bearer and header values MAY be case sensitive

  2. It makes more sense to go for JSON Extractor instead of the Regular Expression Extractor, when it comes to JSON data regular expressions. You should be able to extract the token value using simple JSON Path query like:

    JMeter JSON Extractor

    More information: API Testing With JMeter and the JSON Extractor

Upvotes: 0

prat22
prat22

Reputation: 388

Json Exractor also used to exctract the json resonse value. here below images are helpful for extracting the value from json . storing it in the variable and using it for the header request.

JsonExtractor Control

StoredVariable Used Http Header Request

Upvotes: 2

Related Questions