@otters/monzo
TypeScript icon, indicating that this package has built-in type declarations

2.1.2 • Public • Published

@otters/monzo

Monzo API Wrapper for TypeScript

Brief documentation is below, please consult Monzo's API documentation for more information. Requires Node.js>=16.0.0

Getting Started

First, if you do not have OAuth keys already, you can use the MonzoOAuthAPI class to generate them.

import {MonzoOAuthAPI} from '@otters/monzo';

const oauth = new MonzoOAuthAPI({
	client_id: process.env.MONZO_CLIENT_ID,
	client_secret: process.env.MONZO_CLIENT_SECRET,
	redirect_uri: process.env.MONZO_REDIRECT_URI,
});

Then you can generate a redirect URL to send your user to.

// Let @otters/monzo generate state
const {state, url} = oauth.getOAuthURL();

// Or, generate it yourself
const state = generateState();
const url = oauth.getOAuthURL(state);

Exchanging token

Once you have complete the OAuth flow, you can now exchange tokens for a full MonzoAPI instance.

Make sure to check that state in req.query is the same as the one we previously generated!

// Using our MonzoOAuthAPI class
const oauth = new MonzoOAuthAPI({
	client_id: process.env.MONZO_CLIENT_ID,
	client_secret: process.env.MONZO_CLIENT_SECRET,
	redirect_uri: process.env.MONZO_REDIRECT_URI,
});

const api = await oauth.exchangeAuthorizationCode(code);

Now we can consume api to make requests to the Monzo API.

const user = await api.whoami();

Happy hacking

Readme

Keywords

Package Sidebar

Install

npm i @otters/monzo

Weekly Downloads

40

Version

2.1.2

License

MIT

Unpacked Size

55.8 kB

Total Files

7

Last publish

Collaborators

  • aabbccsmith