0.0.8 • Published 5 years ago

monzo-js v0.0.8

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

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)
});
0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago