简体   繁体   中英

Need to copy API success response to Clipboard in postman

I have to copy API response to the clipboard(ctrl+c). i was trying to do through document.executeCommand in post man test section. But i was getting document is not defined error.

Is there any other way to complete my requirement.

EDIT : I've done it.

Try this:

let template =
`
    <textarea id='copy' style='width:35%'></textarea>
    <script>
        pm.getData(function (error, data)
        {
            var node = document.getElementById('copy');
            node.textContent = data.response;
            var selection = document.getSelection();
            selection.removeAllRanges();
            node.select();
            document.execCommand('copy');
            selection.removeAllRanges();
            document.getElementById('copy').textContent = 'Response copied to clipboard!';
        });
    </script>
`;

pm.visualizer.set(template, {
    response: responseBody
});

Previous answer :

You could print it to the console in a triple-clickable (to highlight) format, making it a bit faster to copy. I use this technique in one of my Collections.

My example responses are in JSON, but the piece I want is nested, so I use this log statement:

console.info(ζ.name + " Results:\n\r", ζ.results.data[0]);

Where the ζ.results.data[0] portion is a convenient, triple-clickable JSON string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM