const axios = require('axios');
const API_BASE = 'https://api.dev.umbrellacost.dev/api';
const USERNAME = 'elisha+testmcpdev@anodot.com';
const PASSWORD = 'Test123!';
async function testDashboardEndpoints() {
try {
console.log('π Authenticating...');
console.log('Using:', USERNAME);
// Authenticate - try Cognito first
let token;
try {
const authResponse = await axios.post(`${API_BASE}/v1/users/signin`, {
username: USERNAME,
password: PASSWORD
}, {
validateStatus: () => true
});
console.log('Auth response status:', authResponse.status);
console.log('Auth response data:', JSON.stringify(authResponse.data, null, 2));
if (authResponse.status === 200) {
// Cognito returns jwtToken
token = authResponse.data.jwtToken || authResponse.data.token || authResponse.data.idToken;
console.log('β
Authenticated successfully (Cognito)');
} else {
throw new Error('Auth failed: ' + JSON.stringify(authResponse.data));
}
} catch (cognitoError) {
console.log('Cognito auth failed, trying Keycloak...');
// Try Keycloak
const authResponse = await axios.post(`${API_BASE}/v1/authentication/token/generate`, {
username: USERNAME,
password: PASSWORD
}, {
headers: {
'Authorization': 'Basic ' + Buffer.from(`${USERNAME}:${PASSWORD}`).toString('base64')
}
});
token = authResponse.data.access_token;
console.log('β
Authenticated successfully (Keycloak)');
}
// Test both endpoints
const endpoints = [
'/dashboards',
'/v1/dashboards'
];
for (const endpoint of endpoints) {
console.log(`\nπ Testing: ${endpoint}`);
// Try different auth formats
const authFormats = [
{ name: 'JWT token only', value: token },
{ name: 'Bearer + token', value: `Bearer ${token}` }
];
for (const authFormat of authFormats) {
console.log(` Trying: ${authFormat.name}`);
try {
const response = await axios.get(`${API_BASE}${endpoint}`, {
headers: {
'Authorization': authFormat.value,
'Content-Type': 'application/json'
},
validateStatus: () => true
});
if (response.status === 200) {
console.log(` β
${endpoint} - SUCCESS with ${authFormat.name}`);
console.log('Response:', JSON.stringify(response.data, null, 2));
break; // Found working format
} else {
console.log(` β Status: ${response.status} - ${response.data?.message || response.statusText}`);
}
} catch (error) {
console.log(` β Error: ${error.message}`);
}
}
}
} catch (error) {
console.error('β Error:', error.response?.data || error.message);
}
}
testDashboardEndpoints();