Add Liabilities to your app
Use Liabilities to fetch data for credit, student loan, and mortgage accounts
In this guide, we'll start from scratch and walk through how to use Liabilities to retrieve information about credit card, PayPal credit, student loan, and mortgage accounts. If you are already familiar with using Plaid and are set up to make calls to the Plaid API, make sure to initialize Link with the liabilities
product and to note that Liabilities supports the use of account subtype filtering; you can then skip ahead to Fetching Liabilities data.
Get Plaid API keys and complete application profile
If you don't already have one, you'll need to create a Plaid developer account. After creating your account, you can find your API keys under the Team Settings menu on the Plaid Dashboard.
You will also need to complete your application profile on the Dashboard. The information in your profile will be shared with users of your application when they manage their connection on the Plaid Portal. Your application profile must be completed before connecting to certain institutions in Production.
Install and initialize Plaid libraries
You can use our official server-side client libraries to connect to the Plaid API from your application:
1// Install via npm2npm install --save plaid
After you've installed Plaid's client libraries, you can initialize them by passing in your client_id
, secret
, and the environment you wish to connect to (Sandbox or Production). This will make sure the client libraries pass along your client_id
and secret
with each request, and you won't need to explicitly include them in any other calls.
1// Using Express2const express = require('express');3const app = express();4app.use(express.json());5
6const { Configuration, PlaidApi, PlaidEnvironments } = require('plaid');7
8const configuration = new Configuration({9 basePath: PlaidEnvironments.sandbox,10 baseOptions: {11 headers: {12 'PLAID-CLIENT-ID': process.env.PLAID_CLIENT_ID,13 'PLAID-SECRET': process.env.PLAID_SECRET,14 },15 },16});17
18const client = new PlaidApi(configuration);
Create an Item in Link
Plaid Link is a drop-in module that provides a secure, elegant authentication flow for each institution that Plaid supports. Link makes it secure and easy for users to connect their bank accounts to Plaid. Note that these instructions cover Link on the web. For instructions on using Link within mobile apps, see the Link documentation.
Using Link, we will create a Plaid Item, which is a Plaid term for a login at a financial institution. An Item is not the same as a financial institution account, although every account will be associated with an Item. For example, if a user has one login at their bank that allows them to access both their checking account and their savings account, a single Item would be associated with both of those accounts.
First, on the client side of your application, you'll need to set up and configure Link. If you want to customize Link's look and feel, you can do so from the Dashboard.
When initializing Link, you will need to specify the products you will be using in the product array.
Liabilities supports the use of the account_filters
parameter to /link/token/create
, which you can use to limit the account types that will be shown in Link to either only credit card accounts, only student loan accounts, or only mortgage accounts. For student loans, use the type loan
and subtype student
. For credit cards, use the type credit
and subtype credit card
. For mortgages, use the type loan
and subtype mortgage
.
Create a link_token
1app.post('/api/create_link_token', async function (request, response) {2 // Get the client_user_id by searching for the current user3 const user = await User.find(...);4 const clientUserId = user.id;5 const request = {6 user: {7 // This should correspond to a unique id for the current user.8 client_user_id: clientUserId,9 },10 client_name: 'Plaid Test App',11 products: ['liabilities'],12 language: 'en',13 webhook: 'https://webhook.example.com',14 redirect_uri: 'https://domainname.com/oauth-page.html',15 country_codes: ['US'],16 };17 try {18 const createTokenResponse = await client.linkTokenCreate(request);19 response.json(createTokenResponse.data);20 } catch (error) {21 // handle error22 }23});
Install Link dependency
1<head>2 <title>Connect a bank</title>3 <script src="https://cdn.plaid.com/link/v2/stable/link-initialize.js"></script>4</head>
Configure the client-side Link handler
1const linkHandler = Plaid.create({2 token: (await $.post('/create_link_token')).link_token,3 onSuccess: (public_token, metadata) => {4 // Send the public_token to your app server.5 $.post('/exchange_public_token', {6 public_token: public_token,7 });8 },9 onExit: (err, metadata) => {10 // Optionally capture when your user exited the Link flow.11 // Storing this information can be helpful for support.12 },13 onEvent: (eventName, metadata) => {14 // Optionally capture Link flow events, streamed through15 // this callback as your users connect an Item to Plaid.16 },17});18
19linkHandler.open();
Get a persistent access_token
Next, on the server side, we need to exchange our public_token
for an access_token
and item_id
. The access_token
will allow us to make authenticated calls to the Plaid API. Doing so is as easy as calling the /item/public_token/exchange
endpoint from our server-side handler. We'll use the client library we configured earlier to make the API call.
Save the access_token
and item_id
in a secure datastore, as they’re used to access Item
data and identify webhooks
, respectively. The access_token
will remain valid unless you actively chose to expire it via rotation or remove the corresponding Item via /item/remove
. The access_token
should be stored securely, and never in client-side code. A public_token
is a one-time use token with a lifetime of 30 minutes, so there is no need to store it.
1app.post('/api/exchange_public_token', async function (2 request,3 response,4 next,5) {6 const publicToken = request.body.public_token;7 try {8 const response = await client.itemPublicTokenExchange({9 public_token: publicToken,10 });11
12 // These values should be saved to a persistent database and13 // associated with the currently signed-in user14 const accessToken = response.data.access_token;15 const itemID = response.data.item_id;16
17 res.json({ public_token_exchange: 'complete' });18 } catch (error) {19 // handle error20 }21});
Fetching Liabilities data
Now that the authentication step is out of the way, we can begin using authenticated endpoints from the Plaid API. For more detailed information on the schema for account information returned, see /liabilities/get
.
1const { LiabilitiesGetRequest } = require('plaid');2
3// Retrieve Liabilities data for an Item4const request: LiabilitiesGetRequest = {5 access_token: accessToken,6};7try {8 const response = await plaidClient.liabilitiesGet(request);9 const liabilities = response.data.liabilities;10} catch (error) {11 // handle error12}
Example response data is below. The data provided is for illustrative purposes; in a Production environment, it would be very unusual for a single institution to provide both credit card and student loan data.
1{2 "accounts": [3 {4 "account_id": "BxBXxLj1m4HMXBm9WZZmCWVbPjX16EHwv99vp",5 "balances": {6 "available": 100,7 "current": 110,8 "iso_currency_code": "USD",9 "limit": null,10 "unofficial_currency_code": null11 },12 "mask": "0000",13 "name": "Plaid Checking",14 "official_name": "Plaid Gold Standard 0% Interest Checking",15 "subtype": "checking",16 "type": "depository"17 },18 {19 "account_id": "dVzbVMLjrxTnLjX4G66XUp5GLklm4oiZy88yK",20 "balances": {21 "available": null,22 "current": 410,23 "iso_currency_code": "USD",24 "limit": 2000,25 "unofficial_currency_code": null26 },27 "mask": "3333",28 "name": "Plaid Credit Card",29 "official_name": "Plaid Diamond 12.5% APR Interest Credit Card",30 "subtype": "credit card",31 "type": "credit"32 },33 {34 "account_id": "Pp1Vpkl9w8sajvK6oEEKtr7vZxBnGpf7LxxLE",35 "balances": {36 "available": null,37 "current": 65262,38 "iso_currency_code": "USD",39 "limit": null,40 "unofficial_currency_code": null41 },42 "mask": "7777",43 "name": "Plaid Student Loan",44 "official_name": null,45 "subtype": "student",46 "type": "loan"47 },48 {49 "account_id": "BxBXxLj1m4HMXBm9WZJyUg9XLd4rKEhw8Pb1J",50 "balances": {51 "available": null,52 "current": 56302.06,53 "iso_currency_code": "USD",54 "limit": null,55 "unofficial_currency_code": null56 },57 "mask": "8888",58 "name": "Plaid Mortgage",59 "official_name": null,60 "subtype": "mortgage",61 "type": "loan"62 }63 ],64 "item": {65 "available_products": ["balance", "credit_details", "investments"],66 "billed_products": [67 "assets",68 "auth",69 "identity",70 "liabilities",71 "transactions"72 ],73 "consent_expiration_time": null,74 "error": null,75 "institution_id": "ins_3",76 "item_id": "eVBnVMp7zdTJLkRNr33Rs6zr7KNJqBFL9DrE6",77 "webhook": "https://www.genericwebhookurl.com/webhook"78 },79 "liabilities": {80 "credit": [81 {82 "account_id": "dVzbVMLjrxTnLjX4G66XUp5GLklm4oiZy88yK",83 "aprs": [84 {85 "apr_percentage": 15.24,86 "apr_type": "balance_transfer_apr",87 "balance_subject_to_apr": 1562.32,88 "interest_charge_amount": 130.2289 },90 {91 "apr_percentage": 27.95,92 "apr_type": "cash_apr",93 "balance_subject_to_apr": 56.22,94 "interest_charge_amount": 14.8195 },96 {97 "apr_percentage": 12.5,98 "apr_type": "purchase_apr",99 "balance_subject_to_apr": 157.01,100 "interest_charge_amount": 25.66101 },102 {103 "apr_percentage": 0,104 "apr_type": "special",105 "balance_subject_to_apr": 1000,106 "interest_charge_amount": 0107 }108 ],109 "is_overdue": false,110 "last_payment_amount": 168.25,111 "last_payment_date": "2019-05-22",112 "last_statement_issue_date": "2019-05-28",113 "last_statement_balance": 1708.77,114 "minimum_payment_amount": 20,115 "next_payment_due_date": "2020-05-28"116 }117 ],118 "mortgage": [119 {120 "account_id": "BxBXxLj1m4HMXBm9WZJyUg9XLd4rKEhw8Pb1J",121 "account_number": "3120194154",122 "current_late_fee": 25.0,123 "escrow_balance": 3141.54,124 "has_pmi": true,125 "has_prepayment_penalty": true,126 "interest_rate": {127 "percentage": 3.99,128 "type": "fixed",129 },130 "last_payment_amount": 3141.54,131 "last_payment_date": "2019-08-01",132 "loan_term": "30 year",133 "loan_type_description": "conventional",134 "maturity_date": "2045-07-31",135 "next_monthly_payment": 3141.54,136 "next_payment_due_date": "2019-11-15",137 "origination_date": "2015-08-01",138 "origination_principal_amount": 425000,139 "past_due_amount": 2304,140 "property_address": {141 "city": "Malakoff",142 "country": "US",143 "postal_code": "14236",144 "region": "NY",145 "street": "2992 Cameron Road",146 }147 "ytd_interest_paid": 12300.4,148 "ytd_principal_paid": 12340.5149 }150 ],151 "student": [152 {153 "account_id": "Pp1Vpkl9w8sajvK6oEEKtr7vZxBnGpf7LxxLE",154 "account_number": "4277075694",155 "disbursement_dates": ["2002-08-28"],156 "expected_payoff_date": "2032-07-28",157 "guarantor": "DEPT OF ED",158 "interest_rate_percentage": 5.25,159 "is_overdue": false,160 "last_payment_amount": 138.05,161 "last_payment_date": "2019-04-22",162 "last_statement_issue_date": "2019-04-28",163 "loan_name": "Consolidation",164 "loan_status": {165 "end_date": "2032-07-28",166 "type": "repayment"167 },168 "minimum_payment_amount": 25,169 "next_payment_due_date": "2019-05-28",170 "origination_date": "2002-08-28",171 "origination_principal_amount": 25000,172 "outstanding_interest_amount": 6227.36,173 "payment_reference_number": "4277075694",174 "pslf_status": {175 "estimated_eligibility_date": "2021-01-01",176 "payments_made": 200,177 "payments_remaining": 160178 },179 "repayment_plan": {180 "description": "Standard Repayment",181 "type": "standard"182 },183 "sequence_number": "1",184 "servicer_address": {185 "city": "San Matias",186 "country": "US",187 "postal_code": "99415",188 "region": "CA",189 "street": "123 Relaxation Road"190 },191 "ytd_interest_paid": 280.55,192 "ytd_principal_paid": 271.65193 }194 ]195 },196 "request_id": "dTnnm60WgKGLnKL"197}
Set up webhook listener
To be alerted to changes in Liabilities data, listen for the DEFAULT_UPDATE
webhook. Upon receiving this webhook, you can call /liabilities/get
again to retrieve updated liabilities information.
Next steps
If you're ready to launch to Production, see the Launch checklist.