npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

monzo-js

v0.0.8

Published

A javascript library for the Monzo API

Downloads

8

Readme

A Monzo API Wrapper

Check out https://monzo-js.surge.sh for the ESDoc

This is an easy to use asynchronous javascript library for the Monzo API.

Installation

Install via npm
npm install monzo-js
ES6
import Monzo from 'monzo-js';

const monzo = new Monzo(accessToken);
Nodejs
const Monzo = require('monzo-js');

const monzo = new Monzo(accessToken);

OAuth API

Authenticate using an authentication token
Monzo.OAuth.usingAuthCode(clientId, clientSecret, redirectURI, authCode).then(({access_token}) => {
	console.log(access_token);
});
Authenticate using a password
Monzo.OAuth.usingPassword(clientId, username, password).then(({access_token}) => {
	console.log(access_token);
});
Authenticate using Client Credentials
Monzo.OAuth.usingClientCredentials(clientId, clientSecret).then(({access_token}) => {
	console.log(access_token);
});
Refreshing tokens
Monzo.OAuth.refreshToken(clientId, clientSecret, refreshToken).then(({access_token}) => {
	console.log(access_token);
});

Accounts API

Find all accounts
monzo.accounts.all().then(accounts => {
	for (const [id, acc] of accounts) {
		console.log(`💵 £${acc.balance} in ${acc.id}`);
	}
});
Find a specific account
monzo.accounts.find(accountId).then(account => {
  console.log(account.id);
});

Transactions API

Find all transactions
account.transactions.all().then(transactions => {
  for (const [id, transaction] of transactions) {
		console.log(transaction.id);
	}
});
Find a specific transaction
account.transactions.find(transactionId).then(transaction =>
	console.log(`Transaction Id: ${transcation.id}`)
);
To query transactions
const q = {since: '2016-01-01T01:45:29.54Z', before: '2017-10-01T01:45:29.54Z', limit: 100};

account.transactions.query(q).then(transactions => {
  for (const [id, transaction] of transactions) {
		console.log(transaction.id);
	}
});
Find transactions before a date
const date = '2016-01-01T01:45:29.54Z';

account.transactions.before(date).then(transactions => {
  for (const [id, transaction] of transactions) {
		console.log(transaction.id);
	}
});
Find transactions since a date

You can use also use after instead of since.

const date = '2016-01-01T01:45:29.54Z';

account.transactions.since(date).then(transactions => {
  for (const [id, transaction] of transactions) {
		console.log(transaction.id);
	}
});
Find transactions after between dates
const since = '2016-01-01T01:45:29.54Z'
const before = '2017-01-01T01:45:29.54Z';

account.transactions.between(since, before).then(transactions => {
  for (const [id, transaction] of transactions) {
		console.log(transaction.id);
	}
});

Balance API

There are two ways to get a balance, through the Account object or fetching directly on the Monzo object.

Find Balance through Account
monzo.accounts.find(accountId).then(account => {
  const balance = account.balance;

	const amount = balance.amount;
	const currency = balance.currency;

	console.log(`${amount} ${currency} in ${account.id}`);
});
Find Balance directly through Monzo Client
monzo.fetchBalance(accountId).then(balance => {
  const balance = account.balance;

	const amount = balance.amount;
	const currency = balance.currency;

	console.log(`${amount} ${currency} in ${accountId}`);
});

Pots API

Find all Pots
monzo.pots.all().then(pots => {
  for (const [id, pot] of pots) {
    console.log(`${pot.name}: ${pot.balance} ${pot.currency}`);
  }
});
Find a specific Pot
monzo.pots.find(potId).then(pot => {
  console.log(`${pot.name}: ${pot.balance} ${pot.currency}`);
});

Webhooks API

Find all webhooks
account.webhooks.all().then(webhooks => {
	for (const [id, webhook] of webhooks) {
		console.log(`Webhook ${id} hooked to ${webhook.url}`);
	}
});
Find a specific webhook
account.webhooks.find(webhookId).then(webhook => {
	console.log(`Webhook ${id} hooked to ${webhook.url}`);
});
Register a webhook
account.webhooks.register(url);
Delete a webhook
account.webhooks.delete(url);

Attachments API

Get upload link for an attachment
monzo.attachments.upload(fileName, fileType).then(res => {
	console.log(res)
});
Register an attachment
monzo.attachments.register(transactionId, fileUrl, fileType).then(res => {
	console.log(res)
});
Deregister an attachment
monzo.attachments.deregister(attachmentId).then(res => {
	console.log(res)
});

Feed API

Create a feed item

This can be done on an Account object

account.createFeedItem('Hello World', 'https://i1.sndcdn.com/artworks-000056416529-3yp7fd-t500x500.jpg');

or on the Monzo object with an accountId

monzo.feed.createItem(accountId, 'Hello world', 'https://i1.sndcdn.com/artworks-000056416529-3yp7fd-t500x500.jpg');
Query feed
monzo.feed.query(accountId, startTime).then(res => {
	console.log(res)
});