Below is the response I am getting from my API and each time I use it, it'll generate a fresh token.
Return Response:-
{"status":true,"msg":"Login successfully","result":{"user_id":"9999940413020708","username":"Akhileshs","email":"[email protected]","last_login":"2016-05-26 06:57:41","first_name":"Akhilesh","last_name":"Singh","gender":"M","dob":"2016-03-30","token":"40df7635009e551beab7"}}
How do I get the token and user id and put these values into next HTTP request
Please let me know any further information is needed from my end.
thanks
3 Answers 3
It's fairly simple:
- Add JSON Path PostProcessor as a child of the request which returns above JSON
Configure JSON Path PostProcessor as follows:
- Variable names: anything meaningful, i.e.
token
- JSON Path Expressions:
$..token
- Other fields may be left as they are
- Variable names: anything meaningful, i.e.
- Refer extracted value as
${token}
where required
References:
- JSONPath - XPath for JSON - JSON Path Language overview and syntax
- Advanced Usage of the JSON Path Extractor in JMeter - some JSON Path tips and tricks (conditional select, working with arrays, matching multiple elements by single query)
That's a scenario that exists in most of the cases wherein you need to extract the authentication token post login. You should use the Regular Expression Extractor post-processor to extract the token, id or anything of this sort. Go to the Thread group and right click and then in the post-processor options you'll find the regular expression extractor option. You'll need to write a regex expression to extract the token or id and give a reference name as well that you can use as a variable in your next requests.
Thanks!
1) Add a Post Processor to parse the access token--> JSON Path Extractor and add the Below Expression
$.result.token
2) Define a variable for to save the access token value, in the JSON Path Extractor to save the parsed value. example variable name is 'token'.
3) whereever the access token is required invoke its value, just be defining as,
${<<Access token variable>>}
example --> ${token}