How to use JSON response from server to send POST request with parameters from JSON (jmeter)

StackOverflow https://stackoverflow.com/questions/23246321

  •  08-07-2023
  •  | 
  •  

Question

I have some specific scenario for retrieving Access Token from API using jmeter. I need to implement following test case and have no idea how to implement this (I am new in jmeter):

  1. Send GET request to server.
  2. Server will return following response: {"RequestToken":"81d1fcd6146d41f69a966a2c083382c7","Expires":3600}
  3. After that I need to send POST request to server with parameter of "RequestToken" from step #2.

Thanks!

Answer of Dmitri T really helped me! Thanks a lot!

Was it helpful?

Solution

If your response {"RequestToken":"81d1fcd6146d41f69a966a2c083382c7","Expires":3600} is the full one you can add a Regular Expression Extractor Post Processor to GET request configured as follows:

  • Reference Name: anything meaningful, i.e. token
  • Regular Expression: {"RequestToken":"(.+?)","Expires":3600}
  • Template: $1$

After that you can refer to extracted value as ${token} or ${__V(token)} in POST request.

If you need to deal with more complex JSON structures I would recommend using JSON Path Extractor available via JMeter Plugin. It allows fetching data from JSON responses in more "intelligent" way as big JSON entities cannot be easily parsed via regular expressions.

In this case relevant JSON Path query will look like $.RequestToken.

See Using the XPath Extractor in JMeter guide for more details (scroll down to Parsing JSON).

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top