I have a pre-req script that does md5 encryption and then passes it back to the server, and when the data is a variable, what is encrypted is the variable name, not the real data of the variable. How to deal with it?
const MD5 = require('crypto-js').MD5
let myVar = pm.variables.get("testmd5"); // or pm.environment.get
const md5String = MD5(myVar).toString();
console.log(md5String);
What do you mean by “pass it back to the server”. Do you need to update the value of the environment variable with the encrypted string? (Which is easy enough, just add pm.environment.set to the end of the script).
I know this way, but sometimes I don’t know what the variable name is, because my pre-req is written inside the collection.
Sometimes it’s a variable, sometimes it’s an environment variable
Local → Data → Environment → Collection → Global - Postman
If you only have the variable set as an environment variable, then it will be fine. If you have the variable with the same name set in multiple locations, then it will read the narrowest value. So a local variable will take precedence over an environment variable if they have the same name.