Skip to content

Instantly share code, notes, and snippets.

@azagniotov
Last active December 16, 2024 06:08
Show Gist options
  • Save azagniotov/210c31540712c10206484d5297616842 to your computer and use it in GitHub Desktop.
Save azagniotov/210c31540712c10206484d5297616842 to your computer and use it in GitHub Desktop.
Downloads all pay-slips from ADP website
/*
This has been tested in Chrome v55.0.2883.95 (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=300');
xhr.setRequestHeader("Access-Control-Allow-Origin", "*"); // CORS policy
xhr.onload = 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);
a.click();
delete a;
}
} else {
console.log('Request failed. Returned status of ' + xhr.status);
}
};
xhr.send();
@corymayer
Copy link

Updated version for 2024:

You need to get your OID by inspecting web requests, and replace YOUR_OID_HERE. I tried to make it generic by calling this API: https://my.adp.com/myadp_prefix/myadpapi/core/v1/version which returns the OID, but the API has some special CORs protection I couldn't figure out.

function sleep(ms) {
   return new Promise(resolve => setTimeout(resolve, ms));
}

var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://my.adp.com/myadp_prefix/payroll/v1/workers/YOUR_OID_HERE/pay-statements?adjustments=yes&numberoflastpaydates=300');
xhr.setRequestHeader("Access-Control-Allow-Origin", "*"); // CORS policy
xhr.onload = async function() {
    if (xhr.status === 200) {
        var rawData = JSON.parse(xhr.responseText);
        var lastPaydate = ""
        var consecutiveEntries = 0
        for (var index = rawData.payStatements.length - 1; index >= 0; --index) {
            var entry = rawData.payStatements[index];
            var date = entry.payDate
            // Handle multiple paystubs on the same day
            var dateSuffix = ""
            if (date === lastPaydate) {
                consecutiveEntries++
                dateSuffix = `-${consecutiveEntries}`
            } else {
                lastPaydate = date
                consecutiveEntries = 0
            }
            var year = entry.payDate.split("-")[0]
            var url = "https://my.adp.com/myadp_prefix" + entry.statementImageUri.href + "?rolecode=employee";

            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();

@jewelhuq
Copy link

jewelhuq commented Sep 5, 2024

Is there any full code can be run from the backend in 2024

@ebertland
Copy link

This is great. Thank you to all who have developed this code. I used the version by @corymayer using Firefox 133.0 on Windows 11 without any modifications except for inserting the OID.

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