API Response :
{
"token" :"eyJ0eXAiOiJKV1QiLCfhfgJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoyLCJ1c2VybmFtZSI6ImRiYWRtaW5AY2lkbnkub3JnIiwiZXhwIjoxNjMyNTY3OTY1LCJlbWFphbCI6ImRiYWRtaW5AY2gjglkbnkub3JnIiwib3JpZ19pYXQiOjE2MzI1NDk5NjV9.3ZtHRy0_jBao7hvQLSVcQuvIMIgjgjg7mmvKqlegS5Jo0-Q"
}
This is in Test
var res = pm.response.json();
pm.environment.set('env',token);
This is expected to save the token in env variable but the token did not work after saving.
What is the issue here?
Try this , it should work:
var res = pm.response.json();
pm.environment.set('env',res.token);
Basically the token you saved contained full response, not the token only.
var {token} = pm.response.json();
pm.environment.set('env',token);
You should access the property , you can access it by pm.response.json().token or by using destructure assignment