Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.2K
Visualizações
How to compute a md5 hash in a pre-request script in PostMan?

I have to set a parameter in my request that is a md5 hash of two other parameters. I think a pre-request script can do the job, but I do not know how to compute a md5 in this script. Any idea?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

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.

over 4 years ago · Santiago Trujillo Relatório

0

FYI, since Postman 4.6.0+ you can no longer include external libraries with $.getScript calls and promise returns, as jQuery was depreciated in favour of Cheerio from 4.6.0.

Therefore if you wish to include a third party library in your pre-request scripts, at present the only way to do so is storing the contents of the file in a environment variable and running eval() in your sript - see why here.

For example:

eval(postman.getEnvironmentVariable("JSSHA")); 

There are however some libraries included with Postman that do not require this workaround, these are listed here.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda