0
votes

I am creating a jmeter load test plan for RESTful API request. I need to use the dynamic API key generated in my first sampler SignIn API in the next set of API requests I am going to create.

Can someone help out with how to pass the selected data parameters from response and input to the another api request in other required format for that post request.

Response Header

WebxxxHeader: {"UserName":"xxxxx","UserID":1,"ApiKey":"ea9a3572-de75-4a85-848a-8fed874f2269","ValidFrom":"2015-06-05 05:54:35","ValidTo":"2015-06-12 05:54:35","UserRole":null,"Password":null,"DeviceToken":null,"DeviceType":null,"IsRetina":false,"UniqueId":null}

Header to be posted in the next set of APIs

WebxxxHeader: {"UserName":"xxxxx","ApiKey":"ea9a3572-de75-4a85-848a-8fed874f2269"}

One more issue here is I have to pass the user email in the header instead of UserName.

Please share advanced JMeter blog references.

Thanks in advance for your suggestions.

1

1 Answers

0
votes

I would suggest searching the web for something like "JMeter correlation" - that should give you the answers you're looking for.

Particular this API key bit can be handled via Regular Expression Extractor postprocessor.

  1. Add Regular Expression Extractor as a child of the request which returns the API Key
  2. Configure it as follows:

    • Field to check: Response Headers
    • Reference Name: anything meaningful, i.e. API_KEY
    • Regular Expression: "ApiKey":"(.+?)"
    • Template: $1$
    • Other fields can be left as is
  3. Add HTTP Header Manager as a child of the second request and configure it as follows:

    • Name: WebxxxHeader
    • Value: `{"UserName":"xxxxx","ApiKey":"${API_KEY}"}

If you testing REST API I think that JSON Path Extractor available via JMeter Plugins could be extremely useful. See Using the XPath Extractor in JMeter guide (scroll to "Parsing JSON") for installation and usage instructions and some form of JSON Path language reference.