Created
January 12, 2023 08:29
-
-
Save AksAman/2df20849104fd1ad5c69ebcd84a779f6 to your computer and use it in GitHub Desktop.
Set postman environment variables from json response
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var jsonData = JSON.parse(responseBody); | |
| let varsToSet = [ | |
| // Put all your keys here (nested don't work as of now) | |
| ] | |
| const setEnvVar = (key, data) => { | |
| if(data[key] !== undefined){ | |
| postman.setEnvironmentVariable(key, data[key]); | |
| return true; | |
| } | |
| return false; | |
| } | |
| varsToSet.forEach((key) => { | |
| let success = setEnvVar(key, jsonData) | |
| tests[key] = success; | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment