Skip to content

Instantly share code, notes, and snippets.

@AksAman
Created January 12, 2023 08:29
Show Gist options
  • Select an option

  • Save AksAman/2df20849104fd1ad5c69ebcd84a779f6 to your computer and use it in GitHub Desktop.

Select an option

Save AksAman/2df20849104fd1ad5c69ebcd84a779f6 to your computer and use it in GitHub Desktop.
Set postman environment variables from json response
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