I'm currently looking to use a rest API script to download attachments currently uploaded in JIRA. I have obtained the link URL in Postman but cannot figure out how to download to my PC.
I have tried the following commands but seem to get errors:
window.open(URL, _blank) - first attempt
https://stackoverflow.com/a/15832662 - second attempt
window.open(URL,_blank)
gives me the following error - ReferenceError: window is not defined
the code found in the stackoverflow link:
function downloadURI(uri, name) {
var link = document.createElement("a");
link.download = name;
link.href = uri;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
delete link;
}
gives me the following error - ReferenceError: document is not defined
Here is my full code from the postman request:
let response = pm.response.json();
let test = response.fields.attachment;
attachmentnum = test.length;
let attachcontent=[];
let attachfilename=[];
console.log(attachmentnum);
for(let i=0; i!==(attachmentnum);i++){
let push1 = response.fields.attachment[i];
attachcontent.push(push1.content)
attachfilename.push(push1.filename)
}
function downloadURI(uri, name) {
var link = document.createElement("a");
link.download = name;
link.href = uri;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
delete link;
}
for(let i=0; i!==(attachmentnum);i++){
downloadURI(attachcontent [i], attachfilename[i])
}
pm.environment.set("attachcontent",JSON.stringify(attachcontent));
pm.environment.set("attachfilename",JSON.stringify(attachfilename));
Any help would be appreciated!