Skip to content

Instantly share code, notes, and snippets.

@weiw11
Last active July 16, 2023 04:12
Show Gist options
  • Save weiw11/02713038f1305fb995e6f36b015e07d2 to your computer and use it in GitHub Desktop.
Save weiw11/02713038f1305fb995e6f36b015e07d2 to your computer and use it in GitHub Desktop.
Export ADP Pay Statements data by accessing their API and saving data as CSV. Requires getting Proxy-Authorization, Cookie, and Statement identifier data manually.
import csv
import requests
# Saves the Dates, Gross and Net Pay, and all Deductions.
def call_adp_statement_api(stmt, headers):
row_data = {}
url = f"https://my.adp.com/myadp_prefix/v1_0/O/A/payStatement/{stmt}"
response = requests.get(url, headers=headers)
# Check if the request was successful
if response.status_code == 200:
data = response.json()
# Check if 'payStatement' key exists in the JSON response
if 'payStatement' in data:
pay_statement = data['payStatement']
# Date
if 'payDate' in pay_statement:
pay_date = pay_statement.get('payDate')
row_data['payDate'] = pay_date
if 'payPeriod' in pay_statement:
pay_period = pay_statement.get('payPeriod')
start_date = pay_period.get('startDate')
row_data['startDate'] = start_date
end_date = pay_period.get('endDate')
row_data['endDate'] = end_date
# Pay
if 'netPayAmount' in pay_statement:
net_pay_amount = pay_statement['netPayAmount'].get('amountValue')
row_data['netPayAmount'] = net_pay_amount
if 'grossPayAmount' in pay_statement:
gross_pay_amount = pay_statement['grossPayAmount'].get('amountValue')
row_data['grossPayAmount'] = gross_pay_amount
# Deductions
if 'deductions' in pay_statement:
deductions = pay_statement['deductions']
# Iterate over each element in the 'deductions' array
for deduction in deductions:
deduction_code_name = deduction.get('CodeName')
deduction_amount = deduction.get('deductionAmount')
if deduction_code_name and deduction_amount:
amount_value = deduction_amount.get('amountValue')
row_data[deduction_code_name] = amount_value
return row_data
def save_to_csv(csv_data):
code_names = set()
for data in csv_data:
code_names.update(data.keys())
# Write the data to a CSV file
filename = "pay_statement_data.csv"
with open(filename, mode='w', newline='') as file:
writer = csv.DictWriter(file, fieldnames=sorted(code_names))
writer.writeheader()
writer.writerows(csv_data)
print(f"Data saved to {filename} successfully.")
def main():
# Define the headers for the HTTP request
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0",
"Accept": "application/json, text/plain, */*",
"Accept-Language": "en-US",
"Accept-Encoding": "gzip, deflate, br",
"Referer": "https//my.adp.com/static/redbox/index.html",
"roleCode": "employee",
"DNT": "1",
"Sec-GPC": "1",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"TE": "trailers",
"Connection": "keep-alive",
"Proxy-Authorization": "", # Insert your data
"Cookie": "", # Insert your data
}
# Statement identifiers can be fetched by calling the API below:
# https://my.adp.com/myadp_prefix/v1_0/O/A/payStatements?adjustments=yes&numberoflastpaydates=160
stmt_urls = [
"###############################",
"###############################",
"###############################",
]
csv_data = []
for i, stmt in enumerate(stmt_urls):
print(f"Processing {stmt}...")
csv_data.append(call_adp_statement_api(stmt, headers))
save_to_csv(csv_data)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment