#!/usr/bin/env node
const https = require('https');
const axios = require('axios');
const axiosInstance = axios.create({
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
timeout: 30000
});
async function compareApiResponses() {
console.log('\n════════════════════════════════════════════════════════════');
console.log(' COMPARING API RESPONSES: WITH AND WITHOUT ACCOUNTID');
console.log('════════════════════════════════════════════════════════════\n');
const baseUrl = 'https://api.umbrellacost.io/api/v1';
try {
// Authenticate
console.log('Authenticating as david+allcloud@umbrellacost.com...');
const authResponse = await axiosInstance.post(`${baseUrl}/users/signin`, {
username: 'david+allcloud@umbrellacost.com',
password: 'Dsamsung1!123'
});
const token = authResponse.data.jwtToken;
const tokenPayload = JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString());
const userKey = tokenPayload.username || tokenPayload.sub;
console.log('✅ Authenticated. User Key:', userKey);
// Build API key for Bank Leumi
const apiKey = `${userKey}:22676:139`;
// Test 1: Query WITH accountId (like Claude Desktop sends)
console.log('\n📊 TEST 1: WITH accountId=696314371547 (Bank Leumi)');
console.log('════════════════════════════════════════════════════');
const params1 = new URLSearchParams({
accountId: '696314371547', // Bank Leumi account
customer_account_key: '22676',
customer_division_id: '139',
startDate: '2025-08-01',
endDate: '2025-08-31',
periodGranLevel: 'month',
groupBy: 'none',
costType: 'cost',
isUnblended: 'true'
});
params1.append('costType', 'discount');
params1.append('excludeFilters[chargetype]', 'Tax');
console.log('Parameters:');
console.log(' accountId: 696314371547');
console.log(' customer_account_key: 22676');
console.log(' customer_division_id: 139');
const response1 = await axiosInstance.get(`${baseUrl}/invoices/caui?${params1}`, {
headers: {
'Authorization': token,
'apikey': apiKey,
'commonparams': JSON.stringify({ isPpApplied: true })
}
});
console.log('\nResponse:');
if (response1.data && response1.data.length > 0) {
response1.data.forEach(item => {
console.log(` ${item.usage_date}: Account ${item.account_id}, Cost: $${item.total_cost.toFixed(6)}`);
});
}
// Test 2: Query WITHOUT accountId
console.log('\n📊 TEST 2: WITHOUT accountId parameter');
console.log('════════════════════════════════════════════════════');
const params2 = new URLSearchParams({
// NO accountId parameter
customer_account_key: '22676',
customer_division_id: '139',
startDate: '2025-08-01',
endDate: '2025-08-31',
periodGranLevel: 'month',
groupBy: 'none',
costType: 'cost',
isUnblended: 'true'
});
params2.append('costType', 'discount');
params2.append('excludeFilters[chargetype]', 'Tax');
console.log('Parameters:');
console.log(' accountId: (not specified)');
console.log(' customer_account_key: 22676');
console.log(' customer_division_id: 139');
const response2 = await axiosInstance.get(`${baseUrl}/invoices/caui?${params2}`, {
headers: {
'Authorization': token,
'apikey': apiKey,
'commonparams': JSON.stringify({ isPpApplied: true })
}
});
console.log('\nResponse:');
if (response2.data && response2.data.length > 0) {
response2.data.forEach(item => {
console.log(` ${item.usage_date}: Account ${item.account_id}, Cost: $${item.total_cost.toFixed(6)}`);
});
}
// Test 3: Query with BOTH accountId AND groupBy=account
console.log('\n📊 TEST 3: WITH accountId AND groupBy=account');
console.log('════════════════════════════════════════════════════');
const params3 = new URLSearchParams({
accountId: '696314371547', // Bank Leumi account
customer_account_key: '22676',
customer_division_id: '139',
startDate: '2025-08-01',
endDate: '2025-08-31',
periodGranLevel: 'month',
groupBy: 'account', // GROUP BY ACCOUNT
costType: 'cost',
isUnblended: 'true'
});
params3.append('costType', 'discount');
params3.append('excludeFilters[chargetype]', 'Tax');
console.log('Parameters:');
console.log(' accountId: 696314371547');
console.log(' customer_account_key: 22676');
console.log(' customer_division_id: 139');
console.log(' groupBy: account');
const response3 = await axiosInstance.get(`${baseUrl}/invoices/caui?${params3}`, {
headers: {
'Authorization': token,
'apikey': apiKey,
'commonparams': JSON.stringify({ isPpApplied: true })
}
});
console.log('\nResponse:');
if (response3.data && response3.data.length > 0) {
response3.data.forEach(item => {
console.log(` ${item.usage_date}: Account ${item.account_id}, Cost: $${item.total_cost.toFixed(6)}`);
});
}
// Summary
console.log('\n\n════════════════════════════════════════════════════════════');
console.log(' ANALYSIS');
console.log('════════════════════════════════════════════════════════════');
console.log('\nExpected from MANUAL_ANSWERS.txt:');
console.log(' Account: 696314371547');
console.log(' August 2025 Cost: $0.002684');
const checkResult = (testName, response) => {
if (response.data && response.data[0]) {
const account = response.data[0].account_id;
const cost = response.data[0].total_cost;
if (account === '696314371547') {
console.log(`\n${testName}: ✅ Correct account`);
} else if (account === '268413799883') {
console.log(`\n${testName}: ❌ WRONG ACCOUNT (268413799883)`);
} else {
console.log(`\n${testName}: ❌ Unknown account (${account})`);
}
if (Math.abs(cost - 0.002684) < 0.01) {
console.log(` Cost: ✅ ~$0.002 range`);
} else if (cost > 10) {
console.log(` Cost: ❌ Way too high ($${cost.toFixed(2)})`);
} else {
console.log(` Cost: ⚠️ $${cost.toFixed(6)}`);
}
}
};
checkResult('TEST 1 (with accountId)', response1);
checkResult('TEST 2 (without accountId)', response2);
checkResult('TEST 3 (with accountId + groupBy)', response3);
} catch (error) {
console.error('\n❌ Error:', error.message);
if (error.response) {
console.error('Response:', error.response.data);
}
}
}
compareApiResponses().catch(console.error);