#!/usr/bin/env node
const https = require('https');
const { URLSearchParams } = require('url');
// Test script to verify MasterBilling data availability across different date ranges
async function makeApiRequest(apiKey, params) {
const queryParams = new URLSearchParams(params);
const url = `https://api.umbrellacost.io/invoices/caui?${queryParams.toString()}`;
return new Promise((resolve, reject) => {
const options = {
hostname: 'api.umbrellacost.io',
path: `/invoices/caui?${queryParams.toString()}`,
method: 'GET',
headers: {
'Accept': 'application/json',
'apikey': apiKey
}
};
const req = https.request(options, (res) => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => {
try {
const json = JSON.parse(data);
resolve({
status: res.statusCode,
data: json,
dataLength: json.Data ? json.Data.length : 0
});
} catch (e) {
resolve({
status: res.statusCode,
error: e.message,
raw: data
});
}
});
});
req.on('error', reject);
req.end();
});
}
async function testMasterBillingDateRanges() {
console.log('Testing MasterBilling account data availability across different date ranges\n');
console.log('=' .repeat(80));
// API key for MasterBilling (account key 21112)
const apiKey = '8bd39ae4-ebea-4426-bd22-07349dd8b962:21112:0';
// Test different date ranges
const dateRanges = [
{ start: '2024-12-01', end: '2024-12-31', desc: 'December 2024' },
{ start: '2024-11-01', end: '2024-11-30', desc: 'November 2024' },
{ start: '2024-10-01', end: '2024-10-31', desc: 'October 2024' },
{ start: '2024-09-01', end: '2024-09-30', desc: 'September 2024' },
{ start: '2024-01-01', end: '2024-12-31', desc: 'Full Year 2024' },
{ start: '2023-12-01', end: '2023-12-31', desc: 'December 2023' },
{ start: '2023-01-01', end: '2023-12-31', desc: 'Full Year 2023' }
];
for (const range of dateRanges) {
console.log(`\nTesting ${range.desc} (${range.start} to ${range.end}):`);
try {
// Test with minimal parameters
const basicResult = await makeApiRequest(apiKey, {
startDate: range.start,
endDate: range.end,
groupBy: 'none',
costType: '["cost","discount"]',
isUnblended: 'true'
});
console.log(` Basic query: Status ${basicResult.status}, Records: ${basicResult.dataLength}`);
if (basicResult.dataLength > 0) {
console.log(` ✓ Found data! First record sample:`);
const firstRecord = basicResult.data.Data[0];
console.log(` - Date: ${firstRecord.date || 'N/A'}`);
console.log(` - Cost: ${firstRecord.cost || firstRecord.Cost || 'N/A'}`);
console.log(` - Service: ${firstRecord.service || firstRecord.Service || 'N/A'}`);
}
// Test with service grouping
const groupedResult = await makeApiRequest(apiKey, {
startDate: range.start,
endDate: range.end,
groupBy: 'service',
costType: '["cost","discount"]',
isUnblended: 'true'
});
console.log(` Grouped query: Status ${groupedResult.status}, Records: ${groupedResult.dataLength}`);
} catch (error) {
console.log(` ✗ Error: ${error.message}`);
}
}
console.log('\n' + '=' .repeat(80));
console.log('\nNow testing the working account (932213950603) for comparison:\n');
// Test the working account for comparison
const workingApiKey = '8bd39ae4-ebea-4426-bd22-07349dd8b962:9350:0';
try {
const workingResult = await makeApiRequest(workingApiKey, {
startDate: '2024-12-01',
endDate: '2024-12-31',
groupBy: 'none',
costType: '["cost","discount"]',
isUnblended: 'true'
});
console.log(`Account 932213950603 (Dec 2024): Status ${workingResult.status}, Records: ${workingResult.dataLength}`);
if (workingResult.dataLength > 0) {
console.log(` ✓ Data available for comparison account`);
}
} catch (error) {
console.log(` Error: ${error.message}`);
}
console.log('\n' + '=' .repeat(80));
console.log('\nDiagnostic Summary:');
console.log('- MasterBilling API key: ' + apiKey);
console.log('- Account key being used: 21112');
console.log('- If all date ranges return 0 records, the issue is with backend data availability');
console.log('- If some ranges have data, adjust your query date range accordingly');
}
// Run the test
testMasterBillingDateRanges().catch(console.error);