Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
I'm sorry that I simplified your example, but import of CryptoJS not needed anymore, it's available natively now. Also, jQuery support has been discontinued since version 4.6.0, in favour of cheerio. https://www.getpostman.com/docs/sandbox. Thank you for good answer : )
Source Link

You can create the following pre-request script provided your parameters are defined environment variables. You would need to tweak this example if they are defined in some other fashion.

// Import the CryptoJS library with jQuery $.getScript("http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js", function() { // Access your env variables like this  var strstr_1 = environment.variable_1 + environment.variable_2; // Or get your //request Useparameters var thestr_2 CryptoJS= scriptrequest.data["foo"] you+ importedrequest.data["bar"];   // Use the CryptoJS var hash = CryptoJS.MD5(strstr_1 + str_2).toString();  // Set the new environment variable  postman.setEnvironmentVariable('hash', hash); }); 

The importCryptoJS works because jQuery isit's available in Postman (as well as lodash, backbone etc).

Accessing environment variables is easy through the environment object.

Setting environment variables is available through the postman object.

After this pre-request has run you can access the hash variable using the normal {{hash}} shorthand.

Also, you can read here about libraries, variables and properties available in Postman.

You can create the following pre-request script provided your parameters are defined environment variables. You would need to tweak this example if they are defined in some other fashion.

// Import the CryptoJS library with jQuery $.getScript("http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js", function() { // Access your env variables like this  var str = environment.variable_1 + environment.variable_2; // Use the CryptoJS script you imported   var hash = CryptoJS.MD5(str).toString();  // Set the new environment variable  postman.setEnvironmentVariable('hash', hash); }); 

The import works because jQuery is available in Postman (as well as lodash, backbone etc).

Accessing environment variables is easy through the environment object.

Setting environment variables is available through the postman object.

After this pre-request has run you can access the hash variable using the normal {{hash}} shorthand.

You can create the following pre-request script provided your parameters are defined environment variables. You would need to tweak this example if they are defined in some other fashion.

// Access your env variables like this var str_1 = environment.variable_1 + environment.variable_2; // Or get your request parameters var str_2 = request.data["foo"] + request.data["bar"];  // Use the CryptoJS var hash = CryptoJS.MD5(str_1 + str_2).toString(); // Set the new environment variable postman.setEnvironmentVariable('hash', hash); 

CryptoJS works because it's available in Postman (as well as lodash, backbone etc).

Accessing environment variables is easy through the environment object.

Setting environment variables is available through the postman object.

After this pre-request has run you can access the hash variable using the normal {{hash}} shorthand.

Also, you can read here about libraries, variables and properties available in Postman.

less ambiguous
Source Link
darryn.ten
  • 7k
  • 3
  • 50
  • 67

You can docreate the following pre-request script provided your parameters are defined environment variables. You would need to tweak this example if they are defined in some other fashion.

// Import the CryptoJS library with jQuery $.getScript("http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js", function() { // Access your env variables like this var str = environment.variable_1 + environment.variable_2; // Use the CryptoJS script you imported var hash = CryptoJS.MD5(str).toString(); // Set the new environment variable postman.setEnvironmentVariable('hash', hash); }); 

The import works because jQuery is available in Postman (as well as lodash, backbone etc).

Accessing environment variables is easy through the environment object.

Setting environment variables is available through the postman object.

After this pre-request has run you can access the hash variable using the normal {{hash}} shorthand.

You can do the following provided your parameters are defined environment variables. You would need to tweak this example if they are defined in some other fashion.

// Import the CryptoJS library with jQuery $.getScript("http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js", function() { // Access your env variables like this var str = environment.variable_1 + environment.variable_2; // Use the CryptoJS script you imported var hash = CryptoJS.MD5(str).toString(); // Set the new environment variable postman.setEnvironmentVariable('hash', hash); }); 

The import works because jQuery is available in Postman (as well as lodash, backbone etc).

Accessing environment variables is easy through the environment object.

Setting environment variables is available through the postman object.

After this pre-request has run you can access the hash variable using the normal {{hash}} shorthand.

You can create the following pre-request script provided your parameters are defined environment variables. You would need to tweak this example if they are defined in some other fashion.

// Import the CryptoJS library with jQuery $.getScript("http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js", function() { // Access your env variables like this var str = environment.variable_1 + environment.variable_2; // Use the CryptoJS script you imported var hash = CryptoJS.MD5(str).toString(); // Set the new environment variable postman.setEnvironmentVariable('hash', hash); }); 

The import works because jQuery is available in Postman (as well as lodash, backbone etc).

Accessing environment variables is easy through the environment object.

Setting environment variables is available through the postman object.

After this pre-request has run you can access the hash variable using the normal {{hash}} shorthand.

Source Link
darryn.ten
  • 7k
  • 3
  • 50
  • 67

You can do the following provided your parameters are defined environment variables. You would need to tweak this example if they are defined in some other fashion.

// Import the CryptoJS library with jQuery $.getScript("http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js", function() { // Access your env variables like this var str = environment.variable_1 + environment.variable_2; // Use the CryptoJS script you imported var hash = CryptoJS.MD5(str).toString(); // Set the new environment variable postman.setEnvironmentVariable('hash', hash); }); 

The import works because jQuery is available in Postman (as well as lodash, backbone etc).

Accessing environment variables is easy through the environment object.

Setting environment variables is available through the postman object.

After this pre-request has run you can access the hash variable using the normal {{hash}} shorthand.