Last active
November 9, 2020 08:15
-
-
Save framegrabber/5e0fa0efaff1c1772d6dac3d14eca50d to your computer and use it in GitHub Desktop.
submit a set of standard expenses for a number of offsets
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
#!/usr/bin/env bash | |
set -eu -o pipefail | |
#Expects the following environment variables to be set | |
#EXPENSIFY_PARTNER_USER_ID= | |
#EXPENSIFY_PARTNER_USER_SECRET= | |
#EXPENSIFY_EMPLOYEE_EMAIL= | |
#EXPENSIFY_SERVER="https://integrations.expensify.com" | |
offsets=("$@") | |
dates=() | |
if [ -z "$offsets" ]; then | |
echo -n "Enter the offsets in days or weeks (-2w, +1w,…) then press [ENTER]: " | |
read -a offsets | |
if [ -z "$offsets" ]; then | |
offsets=("+0w") | |
fi | |
fi | |
for offset in "${offsets[@]}"; do | |
for day in Mon Tue Wed; do | |
dates+=( $(date -v "$offset" -v "$day" +%Y-%m-%d) ) | |
done | |
done | |
for date in "${dates[@]}"; do | |
curl -X POST --fail "$EXPENSIFY_SERVER/Integration-Server/ExpensifyIntegrations" \ | |
--data-urlencode 'requestJobDescription={ | |
"type":"create", | |
"credentials":{ | |
"partnerUserID": "'"$EXPENSIFY_PARTNER_USER_ID"'", | |
"partnerUserSecret": "'"$EXPENSIFY_PARTNER_USER_SECRET"'" | |
}, | |
"inputSettings":{ | |
"type":"expenses", | |
"employeeEmail": "'"$EXPENSIFY_EMPLOYEE_EMAIL"'", | |
"transactionList": [ | |
{ | |
"created": "'"$date"'", | |
"currency": "EUR", | |
"merchant": "20 km @ €0.3 / km", | |
"amount": 600, | |
"category": "Mileage/Parking/Tolls", | |
"tag": "Client Name goes gere:Travel", | |
"billable": false, | |
"reimbursable": true, | |
"comment": "last mile between home and train station in the morning and evening" | |
}, | |
{ | |
"created": "'"$date"'", | |
"currency": "EUR", | |
"merchant": "1 * Germany Day Trip > 8 Hours @ €12.00", | |
"amount": 1200, | |
"category": "Per Diem/Stipend (pre-approved)", | |
"tag": "Client Name goes gere:Travel", | |
"billable": false, | |
"reimbursable": true, | |
"comment": "Day at the client office" | |
} | |
] | |
} | |
}' | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think the script would be much more secure by adding
set -eu -o pipefail
to the top, and--fail
to the curl call.