Postman script to save token to ENV

Saves auth token from API response to env variable automatically

Copy-paste in Postman Test tab

Save to Postman Environment variable(Global)

var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("token", jsonData.token);

Save to collection specific Environment variable

var jsonData = JSON.parse(responseBody);
pm.collectionVariables.set("token", jsonData.token);