0

I need to access the Request Header in Postman to check whether or not a path variable is included in the Postman environment or not.

For example my request might be:

GET https://IP:Port/rest/computers/values?age={{age}}&price={{price}}

i at the End want to check if those Parameters (age,price) are included in the Postman Environment, and if not, Postman should not not consider them for the request, for example if there is no environment variable price specified but age is, Postman changes the request to:

GET https://IP:Port/rest/computers/values?age={{age}}

Thanks for the help in advance!

1 Answer 1

0

You can try something like this pre-request script. This may need some tweaks as I'm writing it without verifying.

def query = "age={{age}}"

if(globals["price"] !== undefined){
  query+="&price={{price}}"
}

postman.setGlobalVariable("path",query)

and use {{path}} in next request.

you can check if instead of undefined you'd be able to use globals["price"].length > 0 If you store your variables in environment not globals use environment["price"] instead

1
  • Hey sorry for the late answer, but thankyou this helps me a lot. Im not quite sure if this might be a more important problem for others too, so i might suggest this as a ticket to solve for the postman team.
    – Leo
    Sep 15, 2017 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.