Skip to content

Instantly share code, notes, and snippets.

@lucasdcrk
Created August 4, 2019 16:14
Show Gist options
  • Save lucasdcrk/00b6201864cbdf963459ec9dacddfb98 to your computer and use it in GitHub Desktop.
Save lucasdcrk/00b6201864cbdf963459ec9dacddfb98 to your computer and use it in GitHub Desktop.
const rp = require('request-promise');
const config = require('./config');
let get_token = new Promise(function (resolve, reject) {
rp({
uri: `https://sync.bankin.com/v2/authenticate?client_id=${config.client.id}&client_secret=${config.client.secret}&email=${config.credentials.email}&password=${config.credentials.password}`,
method: 'POST',
headers: {
'User-Agent': config.headers.user_agent,
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/x-www-form-urlencoded',
'Bankin-Version': config.headers.bankin_version,
'Bankin-Device': config.headers.bankin_device
},
parameters: {
'client_id': config.client.id,
'client_secret': config.client.secret,
'email': config.credentials.email,
'password': config.credentials.password
}
})
.then(function(html){
let json = JSON.parse(html);
let token = json.access_token;
resolve(token);
})
.catch(function(err){
reject(err);
});
});
get_token.then(function (token) {
rp({
uri: `https://sync.bankin.com/v2/accounts?limit=200&client_id=${config.client.id}&client_secret=${config.client.secret}`,
method: 'GET',
headers: {
'User-Agent': config.headers.user_agent,
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/x-www-form-urlencoded',
'Bankin-Version': config.headers.bankin_version,
'Bankin-Device': config.headers.bankin_device,
'Authorization': 'Bearer '+token
},
parameters: {
'limit': 200,
'client_id': config.client.id,
'client_secret': config.client.secret,
}
})
.then(function(html){
let json = JSON.parse(html);
let accounts = json.resources;
let total_balance = 0;
accounts.forEach(function (account) {
account.balance > 0 ? console.log(account.name+' '+account.balance+'€') : null;
total_balance += account.balance;
});
console.log('Total Balance : '+total_balance+'€');
return true;
})
.catch(function(err){
console.log(err)
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment