#!/usr/bin/env node
const https = require('https');
// Test with different date ranges
const testDateRanges = [
{ start: '2025-01-01', end: '2025-09-30', description: 'Full year (same as working curl)' },
{ start: '2025-04-01', end: '2025-09-30', description: 'From April (what MCP uses)' },
{ start: '2023-06-01', end: '2025-09-30', description: 'Full history' }
];
const apiKey = '8bd39ae4-ebea-4426-bd22-07349dd8b962:21112:0';
const authToken = 'eyJraWQiOiJoUFBoZTFRaWM4TklLU1dHcjQ4NEFHK3UwU2c5bCtmUHFWRWZUeCtcL0FcL1k9IiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiI4YmQzOWFlNC1lYmVhLTQ0MjYtYmQyMi0wNzM0OWRkOGI5NjIiLCJhdWQiOiI3aTgyY25wdDQ2OXJjZDkzZmlmMWdsaG5rbSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJldmVudF9pZCI6ImVmMjMyZTlhLWZmNTctNGJjYS04Y2RiLTkyNWMwN2JiNDA2MyIsInRva2VuX3VzZSI6ImlkIiwiYXV0aF90aW1lIjoxNzU5MDczNDAzLCJpc3MiOiJodHRwczpcL1wvY29nbml0by1pZHAudXMtZWFzdC0xLmFtYXpvbmF3cy5jb21cL3VzLWVhc3QtMV9VdjZBck5kU0siLCJjb2duaXRvOnVzZXJuYW1lIjoiOGJkMzlhZTQtZWJlYS00NDI2LWJkMjItMDczNDlkZDhiOTYyIiwiZXhwIjoxNzU5MTU5ODAzLCJpYXQiOjE3NTkwNzM0MDMsImVtYWlsIjoiZGF2aWQrc2FvbGFAdW1icmVsbGFjb3N0LmNvbSJ9.P1Uuu8ot0-5qNvrinz_bw6kPi0PvTyfW6mNop0Ew7NAPWC40JqkqUDCtrf6bCCxkllwIKNbipn_gIDVuKnr5k8HjlLYcG-9tMP9YdE04MZ1X0A5hIFkSOYViE49nSXAkMsHe_Cx-gjaco4RGrKp384T-ZFWpNEsPWDpTuqVe7xwsbzWcNliS0jZdQQhdy1RN0Joh3KoMz7gO7efX4-L31z6WZs96JWNyslPDjE99CNSQlQqtNkQ0qmMxZhAWyYTn0fd7UmenWGg06K5_SJp0-w2rNk5NIB89Z_-11xX6FO51SN3YtSzbAz0ks6FcaYnSDgFWWco6uWz0XWTgSc3Cgw';
async function testDateRange(range) {
return new Promise((resolve) => {
const url = `https://api.umbrellacost.io/api/v1/invoices/caui?startDate=${range.start}&endDate=${range.end}&groupBy=none&periodGranLevel=month&costType=cost`;
console.log(`\nTesting: ${range.description}`);
console.log(`URL: ${url}`);
https.get(url, {
headers: {
'Authorization': authToken,
'apikey': apiKey,
'Accept': 'application/json'
}
}, (res) => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => {
try {
const json = JSON.parse(data);
const recordCount = Array.isArray(json) ? json.length : (json.Data ? json.Data.length : 0);
console.log(`✓ Status: ${res.statusCode}`);
console.log(`✓ Records: ${recordCount}`);
if (recordCount > 0) {
const sample = Array.isArray(json) ? json[0] : json.Data[0];
console.log(`✓ First record date: ${sample.usage_date || sample.date || 'N/A'}`);
} else {
console.log(`✗ Empty response: ${data}`);
}
resolve();
} catch (e) {
console.log(`✗ Error: ${e.message}`);
console.log(`✗ Raw: ${data.substring(0, 100)}`);
resolve();
}
});
}).on('error', (e) => {
console.log(`✗ Request error: ${e.message}`);
resolve();
});
});
}
async function runTests() {
console.log('=== Testing MasterBilling with different date ranges ===');
for (const range of testDateRanges) {
await testDateRange(range);
}
console.log('\n=== Summary ===');
console.log('Check which date ranges return data for MasterBilling account.');
}
runTests();