Created
December 9, 2019 19:59
-
-
Save SpainTrain/0844607a6d004c277efeaf24125280c8 to your computer and use it in GitHub Desktop.
Download multiple twilio invoices from the browser devtools
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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