plaid-node-legacy
A node.js client library for the legacy version of the Plaid API.
This module was forked from plaid-node
version 1.2.0
.
Table of Contents
Install
$ npm install plaid-legacy
Getting started
The module supports all Plaid API endpoints. For complete information about the API, head
to the docs.
Public Endpoints
Public endpoints (category and institution information) require no authentication and can be accessed as follows:
var plaid = require('plaid');
plaid.getCategory(category_id, plaid_env, callback);
plaid.getCategories(plaid_env, callback);
plaid.getInstitution(institution_id, plaid_env, callback);
plaid.getInstitutions(plaid_env, callback);
plaid.searchInstitutions({id: institutionId}, env, callback);
plaid.searchInstitutions({product: plaidProduct, query: searchString}, env, callback);
plaid.searchAllInstitutions({id: institutionId}, env, callback);
plaid.searchAllInstitutions({product: plaidProduct, query: searchString}, env, callback);
plaid_env
dictates which Plaid API environment you will access. Values are:
Environments are exported from the module, i.e.:
var plaid = require('plaid');
console.log(plaid.environments);
Authenticated Endpoints
Authenticated endpoints require a valid client_id
and secret
to access. You can use the sandbox
client_id and secret for testing (test_id
and test_secret
).
All authenticated endpoints are accessible from an instance of a Plaid Client
:
var plaid = require('plaid');
var plaidClient = new plaid.Client(client_id, secret, plaid_env);
The plaid_env
parameter dictates which Plaid API environment you will access. Values are:
Once an instance of the client has been created you use the following methods:
var plaid = require('plaid');
var plaidClient = new plaid.Client(client_id, secret, plaid_env);
plaidClient.addAuthUser(institution_type, credentials, options, callback);
plaidClient.stepAuthUser(access_token, mfaResponse, options, callback);
plaidClient.getAuthUser(access_token, options, callback);
plaidClient.patchAuthUser(access_token, credentials, options, callback);
plaidClient.deleteAuthUser(access_token, options, callback);
plaidClient.addConnectUser(institution_type, credentials, options, callback);
plaidClient.stepConnectUser(access_token, mfaResponse, options, callback);
plaidClient.getConnectUser(access_token, options, callback);
plaidClient.patchConnectUser(access_token, credentials, options, callback);
plaidClient.deleteConnectUser(access_token, options, callback);
plaidClient.addIncomeUser(institution_type, credentials, options, callback);
plaidClient.stepIncomeUser(access_token, mfaResponse, options, callback);
plaidClient.getIncomeUser(access_token, options, callback);
plaidClient.patchIncomeUser(access_token, credentials, options, callback);
plaidClient.deleteIncomeUser(access_token, options, callback);
plaidClient.addInfoUser(institution_type, credentials, options, callback);
plaidClient.stepInfoUser(access_token, mfaResponse, options, callback);
plaidClient.getInfoUser(access_token, options, callback);
plaidClient.patchInfoUser(access_token, credentials, options, callback);
plaidClient.deleteInfoUser(access_token, options, callback);
plaidClient.addRiskUser(institution_type, credentials, options, callback);
plaidClient.stepRiskUser(access_token, mfaResponse, options, callback);
plaidClient.getRiskUser(access_token, options, callback);
plaidClient.patchRiskUser(access_token, credentials, options, callback);
plaidClient.deleteRiskUser(access_token, options, callback);
plaidClient.getBalance(access_token, callback);
plaidClient.upgradeUser(access_token, upgrade_to, options, callback);
plaidClient.exchangeToken(public_token, callback);
plaidClient.getLongtailInstitutions(optionsObject, callback);
plaidClient.getAllInstitutions(optionsObject, callback);
All parameters except options
are required. If the options parameter is omitted, the last argument to the function
will be interpreted as the callback.
Callbacks
For a request that could potentially return a MFA response, callbacks are in the form:
function callback(err, mfaResponse, response) {
}
All add
, step
, and patch
related requests can return a MFA response. upgradeUser
can also return MFA responses.
For delete
, get
, getBalance
, and exchangeToken
requests, callbacks are in the form:
function callback(err, response) {
}
Error Handling
The err
argument passed to either callback style can either be an instance of Error
or a Plaid API error object. An Error
object
is only passed back in the case of a HTTP connection error. The following code distinguishes
between a Plaid error and a standard Error instance:
function callback(err, response) {
if (err != null) {
if (err.code != null) {
console.log(err.code + ': ' + err.message);
} else {
console.log(err.toString());
}
}
}
Examples
Bank of America question-based MFA flow:
var plaid = require('plaid');
var plaidClient = new plaid.Client('test_id', 'test_secret', plaid.environments.tartan);
plaidClient.addAuthUser('bofa', {
username: 'plaid_test',
password: 'plaid_good',
}, function(err, mfaResponse, response) {
if (err != null) {
console.error(err);
} else if (mfaResponse != null) {
plaidClient.stepAuthUser(mfaResponse.access_token, 'tomato', {},
function(err, mfaRes, response) {
console.log(response.accounts);
});
} else {
console.log(response.accounts);
}
});
Chase device-based MFA flow, including using the list:true
option to allow the user select
the device to send their security code to:
plaidClient.addConnectUser('chase', {
username: 'plaid_test',
password: 'plaid_good',
}, {
list: true,
}, function(err, mfaRes, response) {
plaidClient.stepConnectUser(mfaRes.access_token, null, {
send_method: mfaRes.mfa[0],
}, function(err, mfaRes, response) {
plaidClient.stepConnectUser(mfaRes.access_token, '1234', function(err, mfaRes, res) {
console.log('# transactions: ' + res.transactions.length);
console.log('access token: ' + res.access_token);
});
});
});
Retrieve transactions for a connect user for the last thirty days:
plaidClient.getConnectUser(access_token, {
gte: '30 days ago',
}, function(err, response) {
console.log('You have ' + response.transactions.length +
' transactions from the last thirty days.');
});
Associate a new webhook with a connect user (webhook PATCH):
plaidClient.patchConnectUser(access_token, {}, {
webhook: 'http://requestb.in',
}, function(err, mfaResponse, response) {
});
Exchange a public_token
from Plaid Link for a Plaid access token and then
retrieve account data:
plaidClient.exchangeToken(public_token, function(err, res) {
var access_token = res.access_token;
plaidClient.getAuthUser(access_token, function(err, res) {
console.log(res.accounts);
});
});
Exchange a public_token
and account_id
from the Plaid + Stripe ACH
integration for a Plaid access token and a Stripe bank account token:
plaidClient.exchangeToken(public_token, account_id, function(err, res) {
var access_token = res.access_token;
var stripe_token = res.stripe_bank_account_token;
});
Promise Support
You can "promisify" this library using a third-party Promise utility library such as Bluebird.
For example, using Bluebird's promisifyAll
functionality, we can do:
var bluebird = require('bluebird');
var plaid = require('plaid');
bluebird.promisifyAll(plaid);
var client = new plaid.Client('test_id', 'test_secret', plaid.environments.tartan);
client.getAuthUserAsync('test_chase').then(function(authResponse) {
console.log('You have ' + authResponse.accounts.length + ' accounts!');
}).catch(function(err) {
console.error(err);
});
Callbacks that expect more than one argument pose a challenge for Bluebird. For Plaid API functions that may
return an mfa response, use the bluebird multiarg
option to get an array.
var bluebird = require('bluebird');
var plaid = require('plaid');
var client = new plaid.Client('test_id', 'test_secret', plaid.environments.tartan);
var addAuthUserAsync = bluebird.promisify(client.addAuthUser, {context: client, multiArgs: true});
addAuthUserAsync('bofa', {
username: 'plaid_test',
password: 'plaid_good'
}).then(responses => {
var mfaResponse = responses[0];
var response = responses[1];
});
Support
Open an issue!
Tests
$ make test
Code coverage information is written to /coverage
.
License
MIT