My Env includes:
DOMAIN: example.com
PORT: 8008
BASE_API: info/api
How do I create persist an concatenated variable in the ENV table, e.g.
https://$DOMAIN:$PORT/$BASE_API/
(curly braces and
I can do concatenation in pre-request-script, e.g. pm.environment.set(“FULL_PATH”, https://$DOMAIN… )
but doing so the script-base-variable doesn’t show the resolved value to the variable but just e.g. {{FULL_PATH}}user-login/
is there a way to fix this?
Hi @chapman-cheng, Welcome to the community!
As per your use case you can try using variables like below.
https://{{host}}:{{port}}/{{base_api}}/{{relative_api}}
Then, host, port, base_api, relative_api can be set in environment variables.
Hope this helps
4 Likes
Hi @chapman-cheng,
To add on to what @pranavdavar said, you can actually use variables inside of other variables! In addition to variables for URL parts like host
, port
, and path
, you can have another variable named url
with the value https://{{host}}:{{port}}/{{path}}
Then in your request, you can use {{url}}
, and it will resolve correctly.
To accomplish this in a script, you can use the pm.variables.replaceIn
method.
Example:
const url = pm.variables.replaceIn('https://{{host}}:{{port}}/{{path}}');
console.log(url);
Console output:
4 Likes