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

Archived topic — this may be out of date.
Newman has been replaced by the Postman CLI, Postman’s official, signed command-line tool. It runs collections as Newman did, and also lints API specs, runs mocks and monitors, and syncs local files with Postman from your terminal, CI/CD pipeline or coding agent.
Working with an AI coding agent? The Postman plugin lets agents in Claude Code, Cursor, Codex and others design, mock, test and ship APIs with Postman.
For current help, see the Postman docs, try the free Postman tools (no account needed), or join us on Discord.

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!