Retrieve token from response body and save it to env variable

I am trying to save a token after a requests is made so I can refresh the env token variable each run. How do I save the token from the responses body into a env variable for use on other requests. I have this so far.

use the below code as your test script

const responseJson = pm.response.json();
var bodyToken = responseJson.access_token;
pm.environment.set("bodyToken", bodyToken)
2 Likes

That worked beautifully, thank you!

1 Like

Once setting the variable, You can further get it with
pm.variables.get("bodyToken");
use it for further request for chaining