Skip to content

Instantly share code, notes, and snippets.

@framegrabber
Last active November 9, 2020 08:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save framegrabber/5e0fa0efaff1c1772d6dac3d14eca50d to your computer and use it in GitHub Desktop.
Save framegrabber/5e0fa0efaff1c1772d6dac3d14eca50d to your computer and use it in GitHub Desktop.
submit a set of standard expenses for a number of offsets
#!/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
Copy link

ghost commented Nov 13, 2018

I think the script would be much more secure by adding set -eu -o pipefail to the top, and --fail to the curl call.

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