Environment variable does not resolve in pre-request script

Ritwik Chatterjee
Wed, 12 Sep 2018 01:28:57 +0000
Help Hub

Hi,

Looks like environment variables specified as {{env_var}} in URL or request body are NOT resolved before the pre-request script is run.

I am trying to write a pre-request script which will parse the URL to pick up a portion of the URL to be used for encryption/signature. My URL contains an environment variable. During the running of the script, I see that the script picks up the literal string “{{env_var}}” and not the resolved value, and hence the script is failing.

My URL: http://{{my-host}}/resource/{{resource-id}}

My Environment variables which are set:

my-host = localhost:8080
resource-id = 1234

My pre-request script:

 // Grab the request url
 var url = request.url.trim();
 console.log("request url = " + url);

I was expecting the console to log http://localhost:8080/resource/1234 , instead it logs http://{{my-host}}/resource/{{resource-id}}

Please advise.

7 posts - 7 participants