Skip to content

Instantly share code, notes, and snippets.

@cwlls
Forked from azagniotov/download.all.adp.paystubs.js
Last active January 6, 2022 12:11
Show Gist options
  • Save cwlls/62d313914b175b0a6f90f47f20d44af5 to your computer and use it in GitHub Desktop.
Save cwlls/62d313914b175b0a6f90f47f20d44af5 to your computer and use it in GitHub Desktop.
Downloads all pay-slips from ADP website
/*
This has been tested in Chrome v97.0.4692.71 (64-bit)
1. Log into ADP website using the URL: https://my.adp.com/static/redbox/login.html (Make sure you are NOT in Incognito mode)
2. Open Developer Tools console
3. Run the following code in the console:
*/
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 = "paystub-" + 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));
}
@cwlls
Copy link
Author

cwlls commented Jan 6, 2022

I incoporated the change mentioned by Aatoz in the original gist to pause between downloads. I also changed the naming convention for the files to something I liked better. I very much appreciated being able to get all these my pay stubs at once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment