How to capture a query parameter from a redirect URL after a POST request?

I’m working with an OAuth-like flow where I:

  1. Send a POST request to /authorise/authenticate with credentials.
  2. That request responds with a 302 redirect to a GET URL like:
    https://example.com/?code=abc123&state=xyz

I’m running this as part of a Postman collection (potentially via Newman later), and I need to extract the code parameter from that redirected GET URL.

But I’ve found that Postman:

  • Follows redirects automatically
  • Does not expose the final redirected URL in the response object
  • Doesn’t allow me to access it in scripts (pre-request/test)

Is there any way (via scripting, settings, or workarounds) to catch that code from the redirect URL inside Postman?
Just in case - the ultimate goal is to make this collection run fully headless (no UI interaction) so we can integrate it into our CI/CD pipeline using Newman.

How about if you go into your Postman settings and disable “Automatically follow redirects” in the general tab under headers.

Also this topic might be of use.

Pre-request script to automate authorization code grant type - Ask the Experts and Postman Tips - Postman Community

Thank you so much!
It helped!