Search code examples
javascriptpostmanpostman-testcase

postman pm set environment variable


I will get the JWT token as response i need to set that JWT token as environment variable in postman this is my code

pm.test("access_token is working", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.access_token).to.exist;
});

pm.environment.set("jwt_token", pm.test);

and when ever the JWT token changes the postman environment variable should set as that new value


Solution

  • This would be all you need to set the token:

    pm.environment.set("jwt_token", pm.response.json().access_token)
    

    Ensure that you have an environment created and selected in the drop down, in the top right of the app before making the request.