• Stars
    star
    521
  • Rank 84,952 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 11 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Node bindings for Plaid

plaid-node Circle CI npm version

The official node.js client library for the Plaid API.

Table of Contents

Install

$ npm install plaid

Versioning

This release only supports the latest Plaid API version, 2020-09-14, and is generated from our OpenAPI schema.

import { Configuration, PlaidApi, PlaidEnvironments } from 'plaid';

const configuration = new Configuration({
  basePath: PlaidEnvironments.sandbox,
  baseOptions: {
    headers: {
      'PLAID-CLIENT-ID': CLIENT_ID,
      'PLAID-SECRET': SECRET,
    },
  },
});

const client = new PlaidApi(configuration);

For information about what has changed between versions and how to update your integration, head to the API upgrade guide.

The plaid-node client library is typically updated on a monthly basis. The canonical source for the latest version number is the client library changelog.

Data type differences from API and from previous versions

Dates

Dates and datetimes in requests and responses are represented in this version of the Node client library as strings.

Time zone information is required for request fields that accept datetimes. Failing to include time zone information will result in an error. See the following examples for guidance on syntax.

If the API reference documentation for a field specifies format: date, use a string formatted as 'YYYY-MM-DD':

const start_date = '2022-05-05';

If the API reference documentation for a field specifies format: date-time, use a string formatted as 'YYYY-MM-DDTHH:mm:ssZ':

const start_date = '2019-12-12T22:35:49Z';

Enums

While the API and previous library versions represent enums using strings, this current library allows either strings or Node enums.

Old:

products: ['auth', 'transactions'],

Current:

products: ['auth', 'transactions'],

// or

const { Products } = require("plaid");

products: [Products.Auth, Products.Transactions],

Getting started

The module supports all Plaid API endpoints. For complete information about the API, head to the docs.

Most endpoints require a valid client_id and secret as authentication. Attach them via the configuration.

import { Configuration, PlaidApi, PlaidEnvironments } from 'plaid';

const configuration = new Configuration({
  basePath: PlaidEnvironments.sandbox,
  baseOptions: {
    headers: {
      'PLAID-CLIENT-ID': CLIENT_ID,
      'PLAID-SECRET': SECRET,
    },
  },
});

The PlaidEnvironments parameter dictates which Plaid API environment you will access. Values are:

The baseOptions field allows for clients to override the default options used to make requests. e.g.

const configuration = new Configuration({
  basePath: PlaidEnvironments.sandbox,
  baseOptions: {
    // Axios request options
  },
});

Error Handling

All errors can now be caught using try/catch with async/await or through promise chaining.

try {
  await plaidClient.transactionsSync(request);
} catch (error) {
  const err = error.response.data;
}

// or

plaidClient
  .transactionsSync(request)
  .then((data) => {
    console.log(data);
  })
  .catch((e) => {
    console.log(e.response.data);
  });

Note that the full error object includes the API configuration object, including the request headers, which in turn include the API key and secret. To avoid logging your API secret, log only error.data and/or avoid logging the full error.config.headers object.

Examples

Exchange a public_token from Plaid Link for a Plaid access_token and then retrieve account data:

const response = await plaidClient.itemPublicTokenExchange({ public_token });
const access_token = response.data.access_token;
const accounts_response = await plaidClient.accountsGet({ access_token });
const accounts = accounts_response.data.accounts;

Retrieve the last 100 transactions for a transactions user (new, recommended method):

const response = await plaidClient.transactionsSync({
  access_token
});
const transactions = response.data.transactions;
);

Retrieve the transactions for a transactions user for the last thirty days (using the older method):

const now = moment();
const today = now.format('YYYY-MM-DD');
const thirtyDaysAgo = now.subtract(30, 'days').format('YYYY-MM-DD');

const response = await plaidClient.transactionsGet({
  access_token,
  start_date: thirtyDaysAgo,
  end_date: today,
});
const transactions = response.data.transactions;
console.log(
  `You have ${transactions.length} transactions from the last thirty days.`,
);

Get accounts for a particular Item:

const response = await plaidClient.accountsGet({
  access_token,
  options: {
    account_ids: ['123456790'],
  },
});
console.log(response.data.accounts);

Payment Initiation

For more information about this product, head to the Payment Initiation docs.

Create payment recipient using IBAN and address without BACS

const name = 'John Doe';
const iban = 'NL02ABNA0123456789';
const address = {
  street: ['street name 999'],
  city: 'London',
  postal_code: '99999',
  country: 'GB',
};

// Passing bacs as null
const response = await plaidClient.paymentInitiationRecipientCreate({
  name,
  iban,
  address,
});
console.log(response.data.recipient_id);

Create payment recipient using BACS with no IBAN or address

const name = 'John Doe';
const bacs = {
  account: '26207729',
  sort_code: '560029',
};

// For UK recipients, only bacs is required. iban and address are null
const response = await plaidClient.paymentInitiationRecipientCreate({
  name,
  bacs,
});
console.log(response.data.recipient_id);

Create payment

const reference = 'testPayment';
const amount = {
  currency: 'GBP',
  value: 100.0,
};

const response = await plaidClient.paymentInitiationPaymentCreate({
  recipient_id,
  reference,
  amount,
});
console.log(response.data.payment_id);
console.log(response.data.status);

Create Link Token (for Payment Initiation only)

const response = await plaidClient.linkTokenCreate({
  user: {
    client_user_id: '123-test-user-id',
  },
  client_name: 'Plaid Test App',
  products: ['payment_initiation'],
  country_codes: ['GB'],
  language: 'en',
  payment_initiation: {
    payment_id: 'some_payment_id',
  },
});

console.log(response.data.link_token);

Download Asset Report PDF

const pdfResp = await plaidClient.assetReportPdfGet(
  {
    asset_report_token: assetReportToken,
  },
  {
    responseType: 'arraybuffer',
  },
);

fs.writeFileSync('asset_report.pdf', pdfResp.data);

Promise Support

Every method returns a promise, so you can use async/await or promise chaining.

API methods that return either a success or an error can be used with the usual then/catch paradigm, e.g.

plaidPromise
  .then((successResponse) => {
    // ...
  })
  .catch((err) => {
    // ...
  });

For example:

import * as bodyParser from 'body-parser';
import * as express from 'express';
import { Configuration, PlaidApi, PlaidEnvironments } from 'plaid';

const configuration = new Configuration({
  basePath: PlaidEnvironments.sandbox,
  baseOptions: {
    headers: {
      'PLAID-CLIENT-ID': CLIENT_ID,
      'PLAID-SECRET': SECRET,
      'Plaid-Version': '2020-09-14',
    },
  },
});

const plaidClient = new PlaidApi(configuration);

const app = express();
const port = process.env.PORT || 3000;

app.use(
  bodyParser.urlencoded({
    extended: true,
  }),
);
app.use(bodyParser.json());

app.post('/plaid_exchange', (req, res) => {
  var public_token = req.body.public_token;

  return plaidClient
    .itemPublicTokenExchange({ public_token })
    .then((tokenResponse) => tokenResponse.access_token)
    .then((accessToken) => plaidClient.accountsGet({ accessToken }))
    .then((accountsResponse) => console.log(accountsResponse.accounts))
    .catch((error) => {
      const err = error.response.data;

      // Indicates plaid API error
      console.error('/exchange token returned an error', {
        error_type: err.error_type,
        error_code: err.error_code,
        error_message: err.error_message,
        display_message: err.display_message,
        documentation_url: err.documentation_url,
        request_id: err.request_id,
      });

      // Inspect error_type to handle the error in your application
      switch (err.error_type) {
        case 'INVALID_REQUEST':
          // ...
          break;
        case 'INVALID_INPUT':
          // ...
          break;
        case 'RATE_LIMIT_EXCEEDED':
          // ...
          break;
        case 'API_ERROR':
          // ...
          break;
        case 'ITEM_ERROR':
          // ...
          break;
        default:
        // fallthrough
      }

      res.sendStatus(500);
    });
});

app.listen(port, () => {
  console.log(`Listening on port ${port}`);
});

Support

Open an issue!

Contributing

Click here!

License

MIT

More Repositories

1

quickstart

Get up and running with Plaid Link and the API in minutes
TypeScript
537
star
2

pattern

An example end-to-end Plaid integration to create items and fetch transaction data
TypeScript
441
star
3

plaid-python

Python bindings for Plaid
Python
426
star
4

plaid-postman

Postman collection for the Plaid API
HTML
315
star
5

react-plaid-link

React bindings for Plaid Link
TypeScript
264
star
6

deprecated-link

This repository is now deprecated. To integrate with Plaid, visit the docs.
261
star
7

plaid-ruby

Ruby bindings for Plaid
Ruby
225
star
8

plaid-go

go bindings for Plaid
Go
196
star
9

deprecated-async-problem

🔀 Solutions and non-solutions to JavaScript's async problem
JavaScript
186
star
10

react-native-plaid-link-sdk

Plaid Link for React Native
TypeScript
170
star
11

plaid-java

Java bindings for Plaid
Java
129
star
12

plaid-link-ios

Plaid Link iOS SDK
Objective-C
116
star
13

plaid-link-android

Plaid Link Android SDK
Kotlin
100
star
14

tiny-quickstart

A minimal quickstart demonstrating Plaid Link, Balances, and OAuth
JavaScript
77
star
15

plaid-openapi

API version 2020-09-14
74
star
16

support

Plaid Support
66
star
17

plaid-link-examples

Plaid Link Webview, ReactNative examples
Objective-C
60
star
18

pattern-account-funding

Sample code to demonstrate Plaid-powered account funding use cases using the Auth, Identity, and Balance APIs. Includes examples of using Auth partners for end-to-end funds transfers.
TypeScript
44
star
19

envvar

Derive JavaScript values from environment variables
JavaScript
37
star
20

npmserve

fast npm installs for slow clients
Shell
36
star
21

npmserve-server

fast npm installs for slow clients
JavaScript
27
star
22

go-envvar

A go library for managing environment variables. Maps to typed values, supports required and optional vars with defaults.
Go
25
star
23

idv-quickstart

Get up and running with Plaid Identity Verification in minutes
CSS
22
star
24

tutorial-resources

Sample apps and material to go along with Plaid's tutorials
JavaScript
18
star
25

income-sample

Sample app for Income
TypeScript
15
star
26

account-funding-tutorial

TypeScript
13
star
27

sandbox-custom-users

JSON files specifying custom users suitable for testing Plaid integrations on Sandbox
Python
13
star
28

nockingbird

Declarative HTTP mocking (for use with Nock)
CoffeeScript
13
star
29

core-exchange

The Core Exchange spec and generated server code
JavaScript
12
star
30

pattern-transfers

TypeScript
11
star
31

payment-initiation-pattern-app

Payment Initiation demo app for Europe, based on Plaid Pattern
TypeScript
6
star
32

credit-attributes

Attributes that can be calculated using Plaid's credit products
Python
4
star
33

plaid-node-legacy

⚠️This library has been deprecated and archived. Our current libraries can be found at https://plaid.com/docs/libraries/ or https://github.com/plaid
JavaScript
4
star
34

assets-attributes

Attributes that can be calculated using a Plaid Asset Report
Python
3
star
35

plaid-java-legacy

⚠️This library has been deprecated and archived. Our current libraries can be found at https://plaid.com/docs/libraries/ or https://github.com/plaid
Java
3
star
36

plaid-python-legacy

⚠️This library has been deprecated and archived. Our current libraries can be found at https://plaid.com/docs/libraries/ or https://github.com/plaid
Python
3
star
37

plaid-ruby-legacy

⚠️This library has been deprecated and archived. Our current libraries can be found at https://plaid.com/docs/libraries/ or https://github.com/plaid
Ruby
2
star
38

.github

1
star
39

plaid-go-legacy

⚠️This library has been deprecated and archived. Our current libraries can be found at https://plaid.com/docs/libraries/ or https://github.com/plaid
1
star