const axios = require('axios');
async function testNetAmortized() {
const BASE_URL = 'https://api.dev.umbrellacost.dev/api';
const USERNAME = 'elisha+testmcpdev@anodot.com';
const PASSWORD = 'Test123!';
const ACCOUNT_KEY = '111111639';
const DIVISION_ID = '0';
try {
console.log('🔐 Authenticating...\n');
const authResponse = await axios.post(`${BASE_URL}/v1/users/signin`, {
username: USERNAME,
password: PASSWORD
});
const token = authResponse.data.jwtToken;
const tokenPayload = JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString());
const userKey = tokenPayload.sub;
console.log('✅ Authenticated');
console.log(`User Key: ${userKey}\n`);
const startDate = '2025-01-01';
const endDate = '2025-10-08';
const apiKey = `${userKey}:${ACCOUNT_KEY}:${DIVISION_ID}`;
// Test Net Amortized
console.log('═'.repeat(80));
console.log('TEST: Net Amortized (isNetAmortized=true)');
console.log('═'.repeat(80));
const params = {
startDate,
endDate,
isNetAmortized: true,
costType: ['cost', 'discount'],
periodGranLevel: 'month',
groupBy: 'none'
};
console.log('Request params:', JSON.stringify(params, null, 2));
console.log('API Key:', apiKey);
console.log('');
const response = await axios.get(`${BASE_URL}/v2/invoices/cost-and-usage`, {
params: params,
headers: {
'Authorization': token,
'apikey': apiKey
}
});
console.log('✅ Response received');
console.log('Status:', response.status);
console.log('');
if (response.data.data) {
console.log(`Number of records: ${response.data.data.length}`);
if (response.data.data.length > 0) {
const totalCost = response.data.data.reduce((sum, item) => sum + (item.total_cost || 0), 0);
console.log(`Total Cost: $${totalCost.toFixed(2)}`);
console.log('');
console.log('Breakdown by month:');
response.data.data.forEach(item => {
console.log(` ${item.usage_date}: $${item.total_cost.toFixed(2)}`);
});
} else {
console.log('⚠️ WARNING: Data array is EMPTY!');
}
} else {
console.log('⚠️ WARNING: No data.data in response');
console.log('Response structure:', JSON.stringify(response.data, null, 2).substring(0, 500));
}
} catch (error) {
console.error('❌ Error:', error.message);
if (error.response) {
console.error('Status:', error.response.status);
console.error('Data:', JSON.stringify(error.response.data, null, 2));
}
}
}
testNetAmortized();