Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to create an application using the Monzo Bank API
app.get('/transactions/:acc_id', (req, res) => {
const { acc_id } = req.params;
const { token_type, access_token } = accessToken;
const transactionsUrl = `https://api.monzo.com/transactions?expand[]=merchant&account_id=${acc_id}&limit=30`;
request.get(transactionsUrl, {
headers: {
Authorization: `${token_type} ${access_token}`
}
}, (req, response, body) => {
const { transactions } = JSON.parse(body);
res.type('html');
res.write(`
<h1>Transactions</h1>
<table>
<thead>
<th>Description</th>
<th>Amount</th>
<th>Category</th>
</thead>
<tbody>
`);
for(let transaction of transactions) {
const {
description,
amount,
category
} = transaction;
res.write(`
<tr>
<td>${description}</td>
<td>${(amount/100).toFixed(2)}</td>
<td>${category}</td>
</tr>
`);
}
res.write('</tbody></table>');
res.end('<br /><a href="/accounts">&lt; Back to accounts</a>');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.