#!/usr/bin/env node
/**
* Find any available data for Bank Leumi accounts
* Searches through different date ranges to find when data exists
*/
const axios = require('axios');
async function findBankLeumiData() {
console.log('π SEARCHING FOR BANK LEUMI DATA\n');
console.log('=================================\n');
const username = 'david+allcloud@umbrellacost.com';
const password = 'B4*zcI7#F7poEC';
try {
// Authenticate
const authResponse = await axios.post('https://api.umbrellacost.io/api/v1/users/signin', {
username: username,
password: password
});
const token = authResponse.data.jwtToken;
const userKey = JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString()).sub;
console.log('β
Authenticated\n');
// Get Bank Leumi divisions
const tempApiKey = `${userKey}:15808:0`;
const divisionsResponse = await axios.get('https://api.umbrellacost.io/api/v1/users/plain-sub-users', {
headers: {
'Authorization': token,
'apikey': tempApiKey
}
});
const leumiDivisions = divisionsResponse.data.customerDivisions['Bank Leumi'];
console.log(`Found ${leumiDivisions.length} Bank Leumi divisions:\n`);
leumiDivisions.forEach((div, i) => {
console.log(`${i + 1}. ${div.accountName}`);
console.log(` Account ID: ${div.accountId}`);
console.log(` Account Key: ${div.accountKey}`);
console.log(` Division ID: ${div.divisionId}\n`);
});
// Try different approaches to find data
for (const division of leumiDivisions) {
console.log(`\nββββββββββββββββββββββββββββββββββββββββ`);
console.log(`Testing: ${division.accountName}`);
console.log(`ββββββββββββββββββββββββββββββββββββββββ\n`);
const apiKey = `${userKey}:${division.accountKey}:${division.divisionId}`;
// 1. Try full year 2024
console.log('1. Checking full year 2024...');
try {
const response = await axios.get('https://api.umbrellacost.io/api/v1/invoices/caui', {
params: {
startDate: '2024-01-01',
endDate: '2024-12-31',
costType: 'net_amortized',
isPpApplied: false
},
headers: {
'Authorization': token,
'apikey': apiKey,
'commonParams': JSON.stringify({ isPpApplied: false })
}
});
if (response.data?.data?.length > 0) {
const total = response.data.data.reduce((sum, row) => sum + parseFloat(row.cost || 0), 0);
console.log(` β
Found data! Total 2024: $${total.toFixed(2)} (${response.data.data.length} rows)`);
// Group by month
const monthlyData = {};
response.data.data.forEach(row => {
const date = row.date || row.Date || '';
const month = date.substring(0, 7);
if (!monthlyData[month]) monthlyData[month] = 0;
monthlyData[month] += parseFloat(row.cost || 0);
});
console.log(' Monthly breakdown:');
Object.entries(monthlyData).sort().forEach(([month, cost]) => {
if (cost > 0) {
console.log(` ${month}: $${cost.toFixed(2)}`);
}
});
} else {
console.log(' No data for 2024');
}
} catch (error) {
console.log(` Error: ${error.response?.status || error.message}`);
}
// 2. Try 2023
console.log('\n2. Checking year 2023...');
try {
const response = await axios.get('https://api.umbrellacost.io/api/v1/invoices/caui', {
params: {
startDate: '2023-01-01',
endDate: '2023-12-31',
costType: 'net_amortized',
isPpApplied: false
},
headers: {
'Authorization': token,
'apikey': apiKey,
'commonParams': JSON.stringify({ isPpApplied: false })
}
});
if (response.data?.data?.length > 0) {
const total = response.data.data.reduce((sum, row) => sum + parseFloat(row.cost || 0), 0);
console.log(` β
Found data! Total 2023: $${total.toFixed(2)} (${response.data.data.length} rows)`);
} else {
console.log(' No data for 2023');
}
} catch (error) {
console.log(` Error: ${error.response?.status || error.message}`);
}
// 3. Try without date filters (default)
console.log('\n3. Checking without date filters...');
try {
const response = await axios.get('https://api.umbrellacost.io/api/v1/invoices/caui', {
params: {
costType: 'net_amortized',
isPpApplied: false
},
headers: {
'Authorization': token,
'apikey': apiKey,
'commonParams': JSON.stringify({ isPpApplied: false })
}
});
if (response.data?.data?.length > 0) {
console.log(` β
Found ${response.data.data.length} rows`);
// Find date range
const dates = response.data.data.map(row => row.date || row.Date || '').filter(d => d);
if (dates.length > 0) {
dates.sort();
console.log(` Date range: ${dates[0]} to ${dates[dates.length - 1]}`);
}
} else {
console.log(' No data without date filters');
}
} catch (error) {
console.log(` Error: ${error.response?.status || error.message}`);
}
// 4. Try different endpoint
console.log('\n4. Trying cost-and-usage endpoint...');
try {
const response = await axios.get('https://api.umbrellacost.io/api/v1/invoices/cost-and-usage', {
params: {
startDate: '2024-12-01',
endDate: '2024-12-31',
costType: 'net_amortized'
},
headers: {
'Authorization': token,
'apikey': apiKey
}
});
if (response.data?.data?.length > 0) {
const total = response.data.data.reduce((sum, row) => sum + parseFloat(row.cost || 0), 0);
console.log(` β
Found data! December 2024: $${total.toFixed(2)}`);
} else {
console.log(' No data from cost-and-usage endpoint');
}
} catch (error) {
console.log(` Error: ${error.response?.status || error.message}`);
}
}
console.log('\n=================================');
console.log('Search complete');
console.log('=================================\n');
} catch (error) {
console.error('β Error:', error.message);
}
}
// Run the search
findBankLeumiData();