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.
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.