I am new in JMeter. I am trying to set access token dynamically through "Regular Expression Extractor". Basically I am trying to first login and then from it's response , I am trying to get access token and set it in "CreatePost" API.
I am able to get access token using #1 Login API where response is as below.
{ "Message": "Login successfully.", "Status": "Success", "HttpStatus": 200, "Data": { "token_type": "Bearer", "expires_in": 10000, "access_token": "eyJ0eXAiE", "refresh_token": "2bcf1f455f2", "name": "jmeter_test", } }
Could you please help me to get access_token from above response. To get this , I have created "Regular Expression Extractor " and set
Name of Createdvariable : access_token,
Regular Expression: "access_token": "value"
Template $1$
Match No. 1
Could yo please check the regular expression?
Thanks in advance.
If you really need to use the regular expression extractor you need to amend your regular expression to look like:
"access_token":\s+"(\w+)"
where:
(\w+)
matches any number of aplhanumeric characters\s+
matches optional whitespace characterDemo:
More information:
However for JSON responses it makes sense to use JSON Extractor which allows executing arbitrary JsonPath queries to get "interesting" data from the JSON responses, the relevant JsonPath expression will be:
$..access_token
where:
..
is "deep scan" operator, it will find the search term anywhere in the dataaccess_token
- the JSON attribute you're looking forMore information: API Testing With JMeter and the JSON Extractor