97 lines
2.7 KiB
JavaScript
97 lines
2.7 KiB
JavaScript
// Test different AviationStack endpoints to see what works with your subscription
|
|
const https = require('https');
|
|
|
|
const API_KEY = 'b3ca0325a7a342a8f7b214f348dc1d50';
|
|
const FLIGHT = 'AA4563';
|
|
const DATE = '2025-06-02';
|
|
|
|
function testEndpoint(name, url) {
|
|
return new Promise((resolve) => {
|
|
console.log(`\n=== Testing ${name} ===`);
|
|
console.log('URL:', url.replace(API_KEY, '***'));
|
|
|
|
https.get(url, (res) => {
|
|
let data = '';
|
|
|
|
res.on('data', (chunk) => {
|
|
data += chunk;
|
|
});
|
|
|
|
res.on('end', () => {
|
|
try {
|
|
const parsed = JSON.parse(data);
|
|
console.log('Status:', res.statusCode);
|
|
console.log('Response:', JSON.stringify(parsed, null, 2));
|
|
resolve({ name, status: res.statusCode, data: parsed });
|
|
} catch (e) {
|
|
console.error('Parse error:', e);
|
|
resolve({ name, error: e.message });
|
|
}
|
|
});
|
|
}).on('error', (err) => {
|
|
console.error('Request error:', err);
|
|
resolve({ name, error: err.message });
|
|
});
|
|
});
|
|
}
|
|
|
|
async function runTests() {
|
|
console.log('Testing AviationStack API endpoints...');
|
|
console.log('Flight:', FLIGHT);
|
|
console.log('Date:', DATE);
|
|
|
|
// Test different endpoints
|
|
const tests = [
|
|
// Real-time flights (current)
|
|
testEndpoint(
|
|
'Real-time Flights',
|
|
`https://api.aviationstack.com/v1/flights?access_key=${API_KEY}&limit=1`
|
|
),
|
|
|
|
// Flights with IATA code
|
|
testEndpoint(
|
|
'Flights by IATA',
|
|
`https://api.aviationstack.com/v1/flights?access_key=${API_KEY}&flight_iata=${FLIGHT}&limit=1`
|
|
),
|
|
|
|
// Flights with date
|
|
testEndpoint(
|
|
'Flights by IATA + Date',
|
|
`https://api.aviationstack.com/v1/flights?access_key=${API_KEY}&flight_iata=${FLIGHT}&flight_date=${DATE}&limit=1`
|
|
),
|
|
|
|
// Flight schedules
|
|
testEndpoint(
|
|
'Flight Schedules',
|
|
`https://api.aviationstack.com/v1/schedules?access_key=${API_KEY}&flight_iata=${FLIGHT}&limit=1`
|
|
),
|
|
|
|
// Airlines endpoint
|
|
testEndpoint(
|
|
'Airlines (test access)',
|
|
`https://api.aviationstack.com/v1/airlines?access_key=${API_KEY}&limit=1`
|
|
),
|
|
|
|
// Airports endpoint
|
|
testEndpoint(
|
|
'Airports (test access)',
|
|
`https://api.aviationstack.com/v1/airports?access_key=${API_KEY}&limit=1`
|
|
)
|
|
];
|
|
|
|
const results = await Promise.all(tests);
|
|
|
|
console.log('\n\n=== SUMMARY ===');
|
|
results.forEach(result => {
|
|
if (result.data && !result.data.error) {
|
|
console.log(`✅ ${result.name}: SUCCESS`);
|
|
} else if (result.data && result.data.error) {
|
|
console.log(`❌ ${result.name}: ${result.data.error.message || result.data.error}`);
|
|
} else {
|
|
console.log(`❌ ${result.name}: ${result.error}`);
|
|
}
|
|
});
|
|
}
|
|
|
|
runTests();
|