Copy the request URL to the clipboard

Iā€™m using a URL with several variables, and would like to see the full URL that is sent to the server. The main point is for sharing with non-Postman users, such as copy/paste a working example to an email so someone else can just open it in their browser.

i.e. my PM request looks like this: http://{{host}}/my/service({{ref}})?p1={{p1}}
But I want to get the full URL:
http://my.server/my/service(foo)?p1=bar

Yes I can copy/paste and manually fill in the variables, but that get a bit tedious after a while. So I was hoping for an ā€˜expanded URLā€™ link or something. This sounds like an obvious feature but I canā€™t find it in the app nor the forums.

Any help appreciated.

1 Like

Hey @pokrakam

Welcome to the community! :wave:

You could add console.log(pm.request.url.toString()); to the Tests sandbox. This will print the whole resolved URL in the Postman Console.

1 Like

If you didnā€™t want to keep going to the Postman Console, you could have a go with this? Add this template to the Tests tab and it should show the URL and give you a ā€œcopy to clipboardā€ button in the Visualizer. :smile:

let resolvedURL = pm.request.url.toString();

let template = `
<html>
<head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js"></script>
</head>
<body>
    <div>
    <div>
        <pre><code style="width:max-content!important;" id="copyText">${resolvedURL}</code></pre>
    </div>
    <button class="copyButton" type="button" data-clipboard-action="copy" data-clipboard-target="#copyText" style="background:green;color:white;">Copy to Clipboard</button>
    </div>
</body>
</html>
<script>
    var clipboard = new ClipboardJS('.copyButton');

    clipboard.on('success', function(e) {
        e.clearSelection();
        e.trigger.textContent = 'āœ” Copied!';
        window.setTimeout(function() {
            e.trigger.textContent = 'Copy to Clipboard';
        }, 2000);
    });
    clipboard.on('error', function(e) {
        e.clearSelection();
        e.trigger.textContent = 'āœ— Not Copied';
        window.setTimeout(function() {
            e.trigger.textContent = 'Copy to Clipboard';
        }, 2000);
    });

</script>`

pm.visualizer.set(template, pm.response.json())
3 Likes

Hi @danny-dainton
I was happy with the console bit, but this is really neat, thanks! :+1:
I am quite surprised this hasnā€™t been in PM to start with, seems like something obvious folks might want to do.

Youā€™re very welcome.:grin:

Just in case anyone is interested, I just found a third option:
Open the collection via the web rather than the app and you get the expanded URL and even a nice multi-language code template. So I can work in the app, and just refresh the page if I want the URLs for all my requests.

You can also get those same code snippets from the app: