I 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
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With