#!/usr/bin/env node
/**
* Debug findCustomerByAccountId functionality
*/
const axios = require('axios');
async function debugFindAccountId() {
console.log('π DEBUG FIND ACCOUNT ID\n');
console.log('========================\n');
try {
// Authenticate
const authResponse = await axios.post('https://api.umbrellacost.io/api/v1/users/signin', {
username: 'david+allcloud@umbrellacost.com',
password: 'B4*zcI7#F7poEC'
});
const token = authResponse.data.jwtToken;
const userKey = JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString()).sub;
// Get 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 customerDivisions = divisionsResponse.data.customerDivisions;
console.log('Looking for accountId 696314371547 (Bank Leumi Reseller-1):\n');
// Search for the account ID
let found = false;
for (const [customerName, divisions] of Object.entries(customerDivisions)) {
if (Array.isArray(divisions)) {
for (const division of divisions) {
if (division.accountId === '696314371547' || division.accountId === 696314371547) {
console.log(`β
FOUND in customer "${customerName}"`);
console.log(` Division: ${division.accountName}`);
console.log(` Account Key: ${division.accountKey}`);
console.log(` Division ID: ${division.divisionId}`);
console.log(` Account ID: ${division.accountId} (type: ${typeof division.accountId})\n`);
found = true;
break;
}
}
}
if (found) break;
}
if (!found) {
console.log('β NOT FOUND\n');
// Check what Bank Leumi has
console.log('Bank Leumi divisions:\n');
const leumiDivisions = customerDivisions['Bank Leumi'];
if (leumiDivisions) {
leumiDivisions.forEach(div => {
console.log(` ${div.accountName}:`);
console.log(` accountId: ${div.accountId} (type: ${typeof div.accountId})`);
console.log(` accountKey: ${div.accountKey}`);
console.log(` divisionId: ${div.divisionId}\n`);
});
}
}
console.log('βββββββββββββββββββββββββββββββββββββ\n');
console.log('Looking for accountId 533084403826 (Bank Leumi BL Test Env):\n');
// Search for the second account ID
found = false;
for (const [customerName, divisions] of Object.entries(customerDivisions)) {
if (Array.isArray(divisions)) {
for (const division of divisions) {
if (division.accountId === '533084403826' || division.accountId === 533084403826) {
console.log(`β
FOUND in customer "${customerName}"`);
console.log(` Division: ${division.accountName}`);
console.log(` Account Key: ${division.accountKey}`);
console.log(` Division ID: ${division.divisionId}`);
console.log(` Account ID: ${division.accountId} (type: ${typeof division.accountId})\n`);
found = true;
break;
}
}
}
if (found) break;
}
if (!found) {
console.log('β NOT FOUND\n');
}
} catch (error) {
console.error('β Error:', error.response?.data || error.message);
}
}
debugFindAccountId().catch(console.error);