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?
CodePudding user response:
I think you can do like:
pm.test("response is ok", ()=>{
pm.response.to.have.status(200)
})
var jsonData = JSON.parse(responseBody);
var url = jsonData.redirect_uri;
url = url.replace("https://example.com","localhost:8080");
postman.setEnvironmentVariable("custom_url", url );
CodePudding user response:
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 >
Visit the url
</p>
<p >
<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.