How to extract ApiKey from Response Headers and use it in another HTTP request on Jmeter?

728 views Asked by At

I am a new JMeter User. I have been using it to test my APIs. I need to extract API Key from response header and pass it with another request.

For this purpose I have used Regular Expression extractor as a child of the request That Returning the API Key and configured it as follows.

Field Checked: Response Headers
Reference Name: Api_Key
Regular Expression: "ApiKey":"(.+?)"
Template:$1$
Other fields left as is

And Then I have added HTTP Header Manager as a child of the second request and configured it as follows:

Name: apikey
Value: ${Api_Key}

but it's not working.

It couldn't catch the API key and passing the variable itself ("${Api_Key}").

Could anyone please tell me what I am doing wrong and how to fix it or are there any other way to catch the API key.

Thanks!

1

There are 1 answers

0
UBIK LOAD PACK On

What you did looks ok, issue may be in your regexp.

To debug this add a Debug Sampler after the first sampler and add a Default value to regular expression extractor to see if this is what's happening.

Show you response header that contains the key , are you sure there are " ?