Skip to main content

Node.js

On your backend, the Vezgo JS SDK requests user tokens with your client secret, and reads your users' accounts and transactions. It is the same vezgo-sdk-js package as for the web.

Install​

npm install vezgo-sdk-js
const Vezgo = require('vezgo-sdk-js');
// or: import Vezgo from 'vezgo-sdk-js';

Initialize​

const vezgo = Vezgo.init({
clientId: process.env.VEZGO_CLIENT_ID,
secret: process.env.VEZGO_CLIENT_SECRET,
});

Your client ID and secret are in the Client portal. Keep the secret on your backend.

Read a user's data​

Log in with your own stable ID for the user, the same loginName every time. The SDK requests and renews the user's token for you.

const user = vezgo.login('USERNAME_FROM_YOUR_SYSTEM');

const accounts = await user.accounts.getList();
const transactions = await user.transactions.getList({
accountId: accounts[0].id,
from: '2009-01-01',
});

What each call returns is described in Accounts and Transactions. Providers need no user:

const providers = await vezgo.providers.getList();

Serve tokens to your frontend​

A web or mobile app gets user tokens from your backend, through the endpoint it passes as authEndpoint. In Express:

router.post('/vezgo/auth', async (req, res) => {
// req.user is the user logged in to your app
const user = vezgo.login(req.user.id);

res.json({ token: await user.getToken() });
});