const { UmbrellaDualAuth } = require('./dist/dual-auth.js');
const axios = require('axios');
async function getDetailedAugustCosts() {
console.log(`๐ DETAILED AUGUST 2025 ANALYSIS FOR SAOLA ACCOUNT`);
console.log(`๐ค User: david+saola@umbrellacost.com`);
console.log('โ'.repeat(80));
try {
const auth = new UmbrellaDualAuth('https://api.umbrellacost.io/api/v1');
await auth.authenticate({
username: 'david+saola@umbrellacost.com',
password: 'Dsamsung1!'
});
console.log('โ
Authentication successful');
const authHeaders = auth.getAuthHeaders();
// Test different scenarios to match UI behavior
const scenarios = [
{
name: 'UI Default (cost+discount, Aug 1-31, monthly)',
params: {
startDate: '2025-08-01',
endDate: '2025-08-31',
costType: ['cost', 'discount'],
groupBy: 'service',
periodGranLevel: 'month',
isUnblended: true
}
},
{
name: 'Cost Only (Aug 1-31, monthly)',
params: {
startDate: '2025-08-01',
endDate: '2025-08-31',
costType: ['cost'],
groupBy: 'service',
periodGranLevel: 'month',
isUnblended: true
}
},
{
name: 'Daily Granularity (cost+discount, Aug 1-31)',
params: {
startDate: '2025-08-01',
endDate: '2025-08-31',
costType: ['cost', 'discount'],
groupBy: 'service',
periodGranLevel: 'day',
isUnblended: true
}
},
{
name: 'Total by Account (Aug 1-31)',
params: {
startDate: '2025-08-01',
endDate: '2025-08-31',
costType: ['cost', 'discount'],
groupBy: 'account',
periodGranLevel: 'month',
isUnblended: true
}
}
];
for (const scenario of scenarios) {
try {
console.log(`\n๐ ${scenario.name}:`);
console.log(` Params: ${JSON.stringify(scenario.params, null, 2).replace(/\n/g, '\n ')}`);
const response = await axios.get('https://api.umbrellacost.io/api/v1/invoices/caui', {
headers: {
'Authorization': authHeaders.Authorization,
'apikey': authHeaders.apikey,
'Content-Type': 'application/json'
},
params: scenario.params,
timeout: 30000
});
const totalCost = response.data.reduce((sum, item) => sum + (item.total_cost || 0), 0);
console.log(` ๐ต Total: $${totalCost.toLocaleString('en-US', {minimumFractionDigits: 2, maximumFractionDigits: 2})}`);
console.log(` ๐ Entries: ${response.data.length}`);
// Show sample data structure
if (response.data.length > 0) {
const sample = response.data[0];
console.log(` ๐ Sample entry: ${sample.service_name || sample.group_by || sample.account_name} - $${(sample.total_cost || 0).toFixed(2)}`);
}
} catch (error) {
console.log(` โ Error: ${error.response?.status} - ${error.response?.data?.message || error.message}`);
}
}
// Test what the main dashboard might use
console.log(`\n๐ Testing Main Dashboard Pattern:`);
try {
const response = await axios.get('https://api.umbrellacost.io/api/v1/invoices/caui', {
headers: {
'Authorization': authHeaders.Authorization,
'apikey': authHeaders.apikey,
'Content-Type': 'application/json'
},
params: {
startDate: '2025-08-01',
endDate: '2025-08-31',
costType: ['cost', 'discount'],
isUnblended: true
},
timeout: 30000
});
const totalCost = response.data.reduce((sum, item) => sum + (item.total_cost || 0), 0);
console.log(` ๐ต Dashboard Total: $${totalCost.toLocaleString('en-US', {minimumFractionDigits: 2, maximumFractionDigits: 2})}`);
console.log(` ๐ Entries: ${response.data.length}`);
} catch (error) {
console.log(` โ Dashboard Error: ${error.response?.status} - ${error.response?.data?.message || error.message}`);
}
} catch (error) {
console.error(`โ Authentication failed:`, error.message);
}
}
getDetailedAugustCosts().catch(console.error);