Based on Plaid Quickstart and adapted for my needs.
Create a .env file with the following contents. Below I'll explain how to obtain or set these values.
PLAID_CLIENT_ID="xxx"
PLAID_SECRET="yyy"
PLAID_PUBLIC_KEY="zzz"
PLAID_ENV="development"
GSHEET_ID="xxxx_yyyyyyyy_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
GSHEET_TAB_NAME="2019 Taxes"
DEFAULT_ACCOUNT="1234"
NUMBER_OF_DAYS="10"
Obtain your Plaid keys here. Development mode is required to use real bank credentials.
The GSHEET items refer to the spreadsheet you want to write to. The ID can be found in the URL when you're viewing the sheet in your browser.
Of course, it must be a Google Sheet that you have access to. If you have several Google accounts, ensure you use the same account consistently throughout this process.
The new row(s) provided will be written (appended) to the spreadsheet, right after the last row of data.
DEFAULT_ACCOUNT
indicates the last 4 digits of the account you wish to retrieve transactions for.
NUMBER_OF_DAYS
indicates the number of days of transaction history to retrieve. Note that processing transactions will not be included.
- As per usual, install node modules with
npm install
- Run the app with
node index.js
- Go to http://localhost:8000 and connect your bank account.
- Upon success, a file called
plaid_token.json
will be created. You should only have to do this once, unless the token expires, you want to connect a different bank, etc. - This was the only reason we needed to run PlaidSheets in the browser. You can now kill it in the console as well.
- Complete only Step 1 from these instructions. You may have to explicitly set up a Google Cloud account and "product" (even if you only run locally). If you have more than one Google account, ensure you are logged in as the right one when you do this step!
- Upon success, a file called
credentials.json
will be downloaded to your machine. Rename it togsheet_credentials.json
and move it to this folder.
- Now run PlaidSheets as a command-line script with
npm run updateSheet
- The first time you do this, it will direct you to a GSheet authentication flow. Follow the given after "Authorize this app by visiting this url...".
- Paste the code you get at that URL into the command-line. This will create a file called
gsheet_token.json
. - The script will attempt to proceed. If everything works, you'll get "Success!" in the console and an exit code of 0.
Now you have everything you need to run the job on a regular schedule. It's recommended that you run it every x days, where x = NUMBER_OF_DAYS in the .env file. Otherwise you may end up with duplicate transactions.
Personally, I run the included cronJob.sh every morning. I'm on a Mac, so I'm using crontab:
- In the console, type
crontab -e
. Now you're in vim, and you can type something like this:0 7 * * * /FULL_PATH_TO_THIS_REPO/cronjob.sh /FULL_PATH_TO_THIS_REPO >> /FULL_PATH_TO_THIS_REPO/debug.log 2>&1
You can read more about the cron format here. - Save and exit with
:wq
. - Observe the debug.log file in this directory to ensure everything works as planned. Feel free to disable console logging (either in the code or in the cron job instructions) if desired.
Bonus: You can also add conditional formatting to your Google Sheet for color coding (credits vs debits), etc.