postmanpostman-native-app

reading response url and its query parameter in postman


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?


Solution

  • 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];