Skip to content

Instantly share code, notes, and snippets.

@SpainTrain
Created December 9, 2019 19:59
Show Gist options
  • Save SpainTrain/0844607a6d004c277efeaf24125280c8 to your computer and use it in GitHub Desktop.
Save SpainTrain/0844607a6d004c277efeaf24125280c8 to your computer and use it in GitHub Desktop.
Download multiple twilio invoices from the browser devtools
// from https://blog.logrocket.com/programmatic-file-downloads-in-the-browser-9a5186298d5c/
function downloadBlob(blob, filename) {
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename || 'download';
const clickHandler = function() {
setTimeout(() => {
URL.revokeObjectURL(url);
this.removeEventListener('click', clickHandler);
(this.remove && (this.remove(), 1)) ||
(this.parentNode && this.parentNode.removeChild(this));
}, 150)
};
a.addEventListener('click', clickHandler, false);
a.click();
return a;
}
[
"01",
"02",
"03",
"04",
"05",
"06",
"07",
"08",
"09",
"10",
"11",
"12"
].forEach(month =>
fetch(`https://www.twilio.com/console/billing/api/receipt?m=${month}&y=2019`)
.then(res => res.blob())
.then(blob => {
downloadBlob(blob, `twilio-invoice-${month}-2019`);
})
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment