Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting response from Postman in script

image attachedI want to get the value of token from response of Postman and set it to an environment.

My response is showing like :

{
  "success": true,
  "token": "ojkdd"
}

and my script is :

pm.test(responseBody, true)
var jsonData = JSON.parse(responseBody);
console.log(jsonData)

I get the following error :

ReferenceError: responseBody is not defined
like image 206
Angels Avatar asked Jul 09 '26 13:07

Angels


1 Answers

your json data is in pm. So you need to retrieve your JSON data using the below code.

 var jsonData = pm.response.json(); 

 pm.test("Verify Json values", function () { 
  pm.expect(jsonData.success).is.to.equal(true); 
 });

Edit : For setting it to environment as @danny suggested

 pm.environment.set("token", pm.response.json().token)
like image 136
Wisely D Cruizer Avatar answered Jul 11 '26 03:07

Wisely D Cruizer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!