Created
March 11, 2018 16:17
-
-
Save graphicbeacon/15ec55e537013b6f01b801135ee14eb9 to your computer and use it in GitHub Desktop.
How to create an application using the Monzo Bank API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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">< Back to accounts</a>'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment