const axios = require('axios');
async function testUnblendedWithDiscount() {
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}`;
console.log('═'.repeat(80));
console.log('TEST 1: Unblended WITHOUT MSP parameters (direct customer style)');
console.log('═'.repeat(80));
const params1 = {
startDate,
endDate,
isUnblended: true,
costType: ['cost', 'discount'],
periodGranLevel: 'month',
groupBy: 'none'
};
console.log('Request params:', JSON.stringify(params1, null, 2));
console.log('');
const response1 = await axios.get(`${BASE_URL}/v2/invoices/cost-and-usage`, {
params: params1,
headers: {
'Authorization': token,
'apikey': apiKey
}
});
if (response1.data.data && response1.data.data.length > 0) {
console.log(`Jan 2025: $${response1.data.data[0].total_cost.toFixed(2)}`);
}
console.log('\n' + '═'.repeat(80));
console.log('TEST 2: Unblended WITH MSP parameters');
console.log('═'.repeat(80));
const params2 = {
startDate,
endDate,
isUnblended: true,
costType: ['cost', 'discount'],
periodGranLevel: 'month',
groupBy: 'none',
customer_account_key: ACCOUNT_KEY,
customer_division_id: DIVISION_ID
};
console.log('Request params:', JSON.stringify(params2, null, 2));
console.log('');
const response2 = await axios.get(`${BASE_URL}/v2/invoices/cost-and-usage`, {
params: params2,
headers: {
'Authorization': token,
'apikey': apiKey
}
});
if (response2.data.data && response2.data.data.length > 0) {
console.log(`Jan 2025: $${response2.data.data[0].total_cost.toFixed(2)}`);
}
console.log('\n' + '═'.repeat(80));
console.log('COMPARISON');
console.log('═'.repeat(80));
console.log(`Without MSP params: $${response1.data.data[0].total_cost.toFixed(2)}`);
console.log(`With MSP params: $${response2.data.data[0].total_cost.toFixed(2)}`);
if (Math.abs(response1.data.data[0].total_cost - response2.data.data[0].total_cost) < 1) {
console.log('\n✅ Both return the same value');
} else {
console.log('\n⚠️ VALUES DIFFER! This explains the bug.');
}
} 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));
}
}
}
testUnblendedWithDiscount();