Reputation: 83
I would like to write a Google Apps Script that can pull transaction data from my bank and add it to a google spreadsheet. I thought Plaid might be a good option, but I am unable to figure out how I would use the Plaid API within google apps script. Plaid supports Node.js while Google Apps Script uses a JavaScript cloud scripting language.
Google Apps Script does allow you to use external APIs but I believe Plaid makes you add a bank through Link.
Does anyone have any idea of a better way to do this?
Thanks!
Upvotes: 4
Views: 6259
Reputation: 1
Former Plaid employee here. Here's an example of getting balance for the first account for an item. Retrieves every 12 hours in this example, but that logic can be removed.
function getBalance() {
var cache = CacheService.getScriptCache();
var lastUpdated = cache.get('lastUpdated');
// update every 12 hours
if (lastUpdated == null || Date.now() - Date.parse(lastUpdated) > 1000 * 60 * 60 * 12) {
var payload = {
"client_id": "your_client_id",
"secret": "your_secret",
"access_token": "relevant_access_token",
"options": {
"account_ids": ["account_id1", "account_id2"]
}
};
var res = UrlFetchApp.fetch("https://production.plaid.com/accounts/balance/get", {'method': 'post', 'contentType': 'application/json', 'payload': JSON.stringify(payload)});
var obj = JSON.parse(res.getContentText());
var ret = obj.accounts[0].balances.available;
cache.put('lastBalance', String(ret));
cache.put('lastUpdated', new Date().toISOString());
return ret;
}
return Number(cache.get('lastBalance'));
}
Upvotes: 0
Reputation: 427
co-founder of bkper.com here.
We use Plaid to offer direct bank connections to users, offering a Google Apps Script library to easily allow access to data, under a secure OAuth2 layer.
You can use it to access your data without the need to worry about implement Link connections and tokens management :-)
Upvotes: 2
Reputation: 290
founder of Plaid here. I've actually done this for some of my personal projects! What I did was to use one of the quickstart apps to generate an access_token
(doc) then just send a request to /transactions/get
(doc) in the google script. So pretty much the entire script would just be sending one HTTP request then parsing the data and formatting into the google sheets as you see fit.
One gotcha I ran up against is Google sheets actually proxies your requests through their system and heavily caches and rate limits those requests. I think this was in response to the old days where you could practically build a bot net and DOS a site using Google's infra via Sheets.
Hope that helps!
Upvotes: 13