Plaid Node.js Client

42.1.0 · active · verified Tue Apr 21

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

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Plaid client with API credentials and environment, then fetch a list of top institutions using the `institutionsGet` endpoint. It includes basic error handling and best practices for environment variables and API versioning.

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.');

view raw JSON →