#!/usr/bin/env node
/**
* Check what data is available across all accounts
*/
const axios = require('axios');
async function checkAllData() {
console.log('π CHECKING ALL AVAILABLE DATA\n');
console.log('===============================\n');
try {
// Step 1: Authenticate
console.log('1οΈβ£ Authenticating...\n');
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;
console.log('β
Authentication successful\n');
console.log(` User Key: ${userKey}\n`);
// Step 2: Get all divisions
console.log('2οΈβ£ Getting all customer divisions...\n');
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('π All Customers and Divisions:\n');
console.log('βββββββββββββββββββββββββββββββ');
for (const [customerName, divisions] of Object.entries(customerDivisions)) {
console.log(`\nπ’ ${customerName}:`);
if (Array.isArray(divisions)) {
divisions.forEach((div, i) => {
console.log(` Division ${i + 1}:`);
console.log(` Account Key: ${div.accountKey}`);
console.log(` Division ID: ${div.divisionId}`);
console.log(` Account ID: ${div.accountId}`);
});
}
}
console.log('\nβββββββββββββββββββββββββββββββ\n');
// Step 3: Try to get data for the main account
console.log('3οΈβ£ Testing main account data (without customer filter)...\n');
const mainApiKey = `${userKey}:15808:0`;
const dateRanges = [
{ start: '2025-01-01', end: '2025-12-31', label: 'All of 2025' },
{ start: '2024-01-01', end: '2024-12-31', label: 'All of 2024' },
{ start: '2023-01-01', end: '2023-12-31', label: 'All of 2023' }
];
for (const range of dateRanges) {
console.log(`π
Testing ${range.label}...`);
try {
const response = await axios.get('https://api.umbrellacost.io/api/v1/invoices/caui', {
params: {
startDate: range.start,
endDate: range.end,
groupBy: 'none',
costType: ['cost', 'discount']
},
headers: {
'Authorization': token,
'apikey': mainApiKey,
'commonParams': JSON.stringify({ isPpApplied: false })
}
});
if (response.data && Array.isArray(response.data) && response.data.length > 0) {
console.log(` β
Found ${response.data.length} records!`);
// Get unique accounts
const accounts = new Set();
response.data.forEach(row => {
if (row.linkedaccid) accounts.add(row.linkedaccid);
if (row.accountId) accounts.add(row.accountId);
});
console.log(` π Unique accounts: ${accounts.size}`);
if (accounts.size > 0) {
console.log(` Accounts: ${Array.from(accounts).slice(0, 5).join(', ')}${accounts.size > 5 ? '...' : ''}`);
}
// Calculate total
const total = response.data.reduce((sum, row) => sum + parseFloat(row.cost || 0), 0);
console.log(` π° Total: $${total.toFixed(2)}\n`);
} else {
console.log(` β οΈ No data found\n`);
}
} catch (error) {
console.log(` β Error: ${error.response?.status} - ${error.response?.statusText || error.message}\n`);
}
}
} catch (error) {
console.error('β Error:', error.response?.data || error.message);
}
}
// Run the check
checkAllData().catch(console.error);