reading response url and its query parameter in postman

1k Views Asked by At

I have to call an API which redirects to a new URL with response in URL parameters. I want to capture these response URL and its parameters in postman.

Say I call https://endpoint.com/xyz it redirects to https://endpoint.com/redirect?flag=true I want to capture flag value.

Can it be done in postman script? How can I do it in Postman Script?

1

There are 1 best solutions below

1
On BEST ANSWER

In the postman settings, you need to disable Automatically follow redirects.

Then, you need to get the response header of the request that returns the 302. You can then get the flag via a regex (or other string operation, if you prefer)

let location = postman.getResponseHeader("Location")

let flag = location.match(/flag=(.*)(&|$)/)[1];