Skip to content

Instantly share code, notes, and snippets.

@graphicbeacon
Created March 11, 2018 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save graphicbeacon/15ec55e537013b6f01b801135ee14eb9 to your computer and use it in GitHub Desktop.
Save graphicbeacon/15ec55e537013b6f01b801135ee14eb9 to your computer and use it in GitHub Desktop.
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