2

If request is using an environment variable then when using pm.request.url.toString() inside a Pre-requisite Script it outputs the query with the placeholder and not it's actual value. meaning it will output https://somesite.com/api/v3/{{env_variable}} instead of https://somesite.com/api/v3/liststuff or whatever.

Is there anyway to get the URL with the value and not the placeholder?

poopa
  • 31
  • 1

1 Answers1

1

Request is not resolved in the pre-request script since the variables could be further modified there. But you can use the postman-collection library within the scripts to resolve the request yourself.

Thanks harryi3t for posting this script on GitHub

https://github.com/postmanlabs/postman-app-support/issues/3322

Here's a sample script

let sdk = require('postman-collection'),
newRequest = new sdk.Request(pm.request.toJSON()),
resolvedRequest = newRequest.toObjectResolved(null, [pm.variables.toObject()], { ignoreOwnVariables: true });
// prints the resolved request to console. Please check DevTools to see the structure
console.log({ resolvedRequest });

Kindly refer screenshot for the same in which custId takes value from placeholder and resolved in pre request also before excuting actual request