const axios = require('axios');
async function testAnomalyCurl() {
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\n');
console.log('📊 Testing anomaly-detection with query parameters...\n');
const response = await axios.get(`${BASE_URL}/v1/anomaly-detection`, {
params: {
startDate: '2025-09-01',
endDate: '2025-10-07',
isPpApplied: false
},
headers: {
'Authorization': token,
'apikey': `${userKey}:${ACCOUNT_KEY}:${DIVISION_ID}`,
'Content-Type': 'application/json',
'commonParams': JSON.stringify({isPpApplied: false})
}
});
console.log('✅ Response received\n');
console.log('=== RESPONSE ===');
console.log(`Status: ${response.status}`);
if (response.data && response.data.anomalies) {
console.log(`Anomalies count: ${response.data.anomalies.length}`);
if (response.data.anomalies.length > 0) {
console.log('\nFirst anomaly:');
const firstAnomaly = response.data.anomalies[0];
console.log(` UUID: ${firstAnomaly.uuid}`);
console.log(` Account: ${firstAnomaly.accountId}`);
console.log(` Service: ${firstAnomaly.serviceName}`);
console.log(` Type: ${firstAnomaly.anomalyType}`);
console.log(` Current Cost: $${firstAnomaly.currentCost?.toFixed(2)}`);
console.log(` Total Cost Impact: $${firstAnomaly.totalCostImpact?.toFixed(2)}`);
console.log(` Percent Change: ${firstAnomaly.percentChange?.toFixed(2)}%`);
}
} else {
console.log('Response data:', JSON.stringify(response.data, null, 2));
}
} catch (error) {
console.error('❌ Error:', error.message);
if (error.response) {
console.error('Status:', error.response.status);
console.error('Data:', error.response.data);
}
}
}
testAnomalyCurl();