Check out https://monzo-js.surge.sh for the ESDoc
This is an easy to use asynchronous javascript library for the Monzo API.
- Installation
- OAuth API
- Accounts API
- Transactions API
- Balance API
- Pots API
- Webhooks API
- Attachments API
- Feed API
npm install monzo-js
import Monzo from 'monzo-js';
const monzo = new Monzo(accessToken);
const Monzo = require('monzo-js');
const monzo = new Monzo(accessToken);
Monzo.OAuth.usingAuthCode(clientId, clientSecret, redirectURI, authCode).then(({access_token}) => {
console.log(access_token);
});
Monzo.OAuth.usingPassword(clientId, username, password).then(({access_token}) => {
console.log(access_token);
});
Monzo.OAuth.usingClientCredentials(clientId, clientSecret).then(({access_token}) => {
console.log(access_token);
});
Monzo.OAuth.refreshToken(clientId, clientSecret, refreshToken).then(({access_token}) => {
console.log(access_token);
});
monzo.accounts.all().then(accounts => {
for (const [id, acc] of accounts) {
console.log(`đź’µ ÂŁ${acc.balance} in ${acc.id}`);
}
});
monzo.accounts.find(accountId).then(account => {
console.log(account.id);
});
account.transactions.all().then(transactions => {
for (const [id, transaction] of transactions) {
console.log(transaction.id);
}
});
account.transactions.find(transactionId).then(transaction =>
console.log(`Transaction Id: ${transcation.id}`)
);
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);
}
});
const date = '2016-01-01T01:45:29.54Z';
account.transactions.before(date).then(transactions => {
for (const [id, transaction] of transactions) {
console.log(transaction.id);
}
});
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);
}
});
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);
}
});
There are two ways to get a balance, through the Account object or fetching directly on the Monzo object.
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}`);
});
monzo.fetchBalance(accountId).then(balance => {
const balance = account.balance;
const amount = balance.amount;
const currency = balance.currency;
console.log(`${amount} ${currency} in ${accountId}`);
});
monzo.pots.all().then(pots => {
for (const [id, pot] of pots) {
console.log(`${pot.name}: ${pot.balance} ${pot.currency}`);
}
});
monzo.pots.find(potId).then(pot => {
console.log(`${pot.name}: ${pot.balance} ${pot.currency}`);
});
account.webhooks.all().then(webhooks => {
for (const [id, webhook] of webhooks) {
console.log(`Webhook ${id} hooked to ${webhook.url}`);
}
});
account.webhooks.find(webhookId).then(webhook => {
console.log(`Webhook ${id} hooked to ${webhook.url}`);
});
account.webhooks.register(url);
account.webhooks.delete(url);
monzo.attachments.upload(fileName, fileType).then(res => {
console.log(res)
});
monzo.attachments.register(transactionId, fileUrl, fileType).then(res => {
console.log(res)
});
monzo.attachments.deregister(attachmentId).then(res => {
console.log(res)
});
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');
monzo.feed.query(accountId, startTime).then(res => {
console.log(res)
});