urlpostreturnpostmantweak

Postman - change part of return of a POST to localhost


I'm making a POST request to a login API in Postman, with body parameters, and it returns like this:

{
"redirect_uri": "https://example.com/authorization?etc=etc..."
}

I would like Postman to format for me the return to:

{
"redirect_uri": "localhost:8080/authorization?etc=etc..."
}

Is it possible?


Solution

  • I managed to do it using visualize and the example from Malsha Liyanage:

    On tests put this:

    template = `
    <script>
            function copyUrl() {
                let copyText = document.querySelector("#code");
                console.log(copyText)
                copyText.select();    
                document.execCommand("copy");
            }
        </script>
        <div style="margin-left: 50px; margin-top:50px;">
            <p class="block">
                Visit the url
            </p>
            <p class="block">
                <textarea cols="90" id="code">{{response}}</textarea>
            </p>
            <button onclick="copyUrl()">Copy Url</button>
        </div>
    
    
    `;
    var jsonData = JSON.parse(responseBody);
    
    var url = jsonData.redirect_uri;
    url = url.replace("https://example.com","localhost:8080");
    // Set visualizer
    pm.visualizer.set(template, {
        response: url
    });
    

    And on Visualize, press button copy to get the url and paste on browser, very simple.