Plaid Node.js Client
The `plaid` package is the official Node.js client library for interacting with the Plaid API, providing programmatic access to financial data. Currently at version 42.1.0, the library is actively maintained with updates typically released on a monthly basis, aligning with Plaid API developments. It is generated directly from Plaid's OpenAPI schema, ensuring comprehensive coverage of the latest API version (specifically `2020-09-14`). A key differentiator is its direct support for various Plaid environments (sandbox, development, production) and its use of semantic versioning, with major version increments indicating potentially breaking changes. This client simplifies authentication and API request handling, abstracting the underlying HTTP requests and providing TypeScript type definitions for robust development.
Common errors
-
Plaid API Error: { "error_code": "INVALID_CREDENTIALS", "error_message": "client_id or secret is invalid", ... }cause The Plaid API client was initialized with incorrect or missing `PLAID-CLIENT-ID` or `PLAID-SECRET` headers.fixVerify that your `PLAID_CLIENT_ID` and `PLAID_SECRET` environment variables (or hardcoded values during development) exactly match your credentials from the Plaid Dashboard for the chosen environment (Sandbox, Development, or Production). -
TypeError: Cannot read properties of undefined (reading 'Configuration') OR PlaidApi is not a constructor
cause Attempting to use CommonJS `require()` syntax with a library that is primarily designed for ES Modules (ESM) and uses named exports, especially in a modern Node.js project where `type: "module"` is set in `package.json`.fixSwitch to ES Module `import` statements: `import { Configuration, PlaidApi, PlaidEnvironments } from 'plaid';`. If you must use CommonJS, ensure your environment supports it correctly, or investigate if an older version of the library explicitly supported CommonJS exports. -
Plaid API Error: { "error_code": "INVALID_INPUT", "error_message": "'start_date' must be in the format 'YYYY-MM-DD'", ... }cause A date field in an API request (e.g., `start_date`, `end_date` for transactions) was not provided in the required `YYYY-MM-DD` string format.fixReview the specific endpoint documentation for the correct date format. Ensure all date parameters are formatted as `YYYY-MM-DD` strings. For datetimes, use `YYYY-MM-DDTHH:mm:ssZ`.
Warnings
- breaking Major version bumps of the `plaid-node` client library (e.g., from v8 to v9, or v9 to v42) often introduce breaking changes. Version 9.0.0, released in August 2021, represented a significant interface change due to the transition to an OpenAPI spec-generated client. Always consult the client library changelog and migration guide when upgrading major versions.
- gotcha The `plaid-node` client library is explicitly designed to support the `2020-09-14` Plaid API version. Using an outdated client library or implicitly relying on an older API version can lead to unexpected behavior or missing features.
- gotcha When handling errors, logging the full error object directly (e.g., `console.error(error)`) can expose sensitive API keys and secrets embedded in `error.response.config.headers`.
- gotcha Dates and datetimes in Plaid API requests have strict string formatting requirements. `format: date` requires `'YYYY-MM-DD'` and `format: date-time` requires `'YYYY-MM-DDTHH:mm:ssZ'`. Failing to adhere to these formats or omitting time zone information for datetimes will result in an API error.
Install
-
npm install plaid -
yarn add plaid -
pnpm add plaid
Imports
- Configuration
const Configuration = require('plaid').Configuration;import { Configuration } from 'plaid'; - PlaidApi
import PlaidApi from 'plaid';
import { PlaidApi } from 'plaid'; - PlaidEnvironments
const PlaidEnvironments = require('plaid').PlaidEnvironments;import { PlaidEnvironments } from 'plaid';
Quickstart
import { Configuration, PlaidApi, PlaidEnvironments, Products, CountryCode } from 'plaid';
// Replace with your actual Plaid API credentials. Consider using environment variables.
const CLIENT_ID = process.env.PLAID_CLIENT_ID ?? 'your_client_id';
const SECRET = process.env.PLAID_SECRET ?? 'your_secret';
// Configure the Plaid client
const configuration = new Configuration({
basePath: PlaidEnvironments.sandbox, // Or PlaidEnvironments.production for live data
baseOptions: {
headers: {
'PLAID-CLIENT-ID': CLIENT_ID,
'PLAID-SECRET': SECRET,
'Plaid-Version': '2020-09-14', // Recommended to explicitly set the API version
},
},
});
const plaidClient = new PlaidApi(configuration);
async function getPlaidInstitutions() {
try {
// Define a request to fetch some institutions
const request = {
country_codes: [CountryCode.Us],
products: [Products.Auth],
count: 5,
offset: 0,
};
const response = await plaidClient.institutionsGet(request);
console.log('Successfully fetched top 5 Institutions:');
response.data.institutions.forEach(inst => console.log(`- ${inst.name} (ID: ${inst.institution_id})`));
return response.data.institutions;
} catch (error: any) {
if (error.response) {
// Log only necessary parts to avoid exposing secrets in error.response.config.headers
console.error('Plaid API Error:', error.response.data);
} else {
console.error('Plaid Client Error:', error.message);
}
throw error;
}
}
// Run the example
PlaidEnvironments.sandbox === configuration.basePath ?
getPlaidInstitutions().then(() => console.log('\nExample complete using Sandbox environment.')) :
console.warn('Warning: Not running institution fetch in non-sandbox environment for quickstart.');