Skip to content

Instantly share code, notes, and snippets.

@bvanpeski
Created December 29, 2020 19:20
Show Gist options
  • Save bvanpeski/bb19c815d25d3e49a083557752ae3017 to your computer and use it in GitHub Desktop.
Save bvanpeski/bb19c815d25d3e49a083557752ae3017 to your computer and use it in GitHub Desktop.
Download all ADP Paystubs

From https://gist.github.com/azagniotov/210c31540712c10206484d5297616842#gistcomment-2862672

In Vivaldi (chromium engine) this stops after 10. It looks like there's some sort of block to prevent excessive downloads. You need to await the downloads to get past this.

var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://my.adp.com/v1_0/O/A/payStatements?adjustments=yes&numberoflastpaydates=999');
xhr.setRequestHeader("Access-Control-Allow-Origin", "*"); // CORS policy
xhr.onload = async function() {
    if (xhr.status === 200) {
        var rawData = JSON.parse(xhr.responseText);

        for (var index = rawData.payStatements.length - 1; index >= 0; --index) {
            var entry = rawData.payStatements[index];
            var url = "https://my.adp.com" + entry.statementImageUri.href.substring(3);
            var a = document.createElement('a');

            var trueIndex = (rawData.payStatements.length - index);
            if (trueIndex < 10) {
                trueIndex = "00" + trueIndex;
            } else if (trueIndex < 100) {
                trueIndex = "0" + trueIndex;
            }

            a.download = "payslip.no." + trueIndex + ".from." + entry.payDate + ".pdf";
            a.href = url;
            document.body.appendChild(a);

            await sleep(500);
            a.click();
            delete a;
        }
    } else {
        console.log('Request failed.  Returned status of ' + xhr.status);
    }
};
xhr.send();

function sleep(ms) {
   return new Promise(resolve => setTimeout(resolve, ms));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment