-
Notifications
You must be signed in to change notification settings - Fork 0
/
second.js
31 lines (25 loc) · 1007 Bytes
/
second.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const axios = require('axios');
const API_KEY = 'YOUR_API_KEY'; // Replace with your Skyscanner API key
const ORIGIN = 'NYC'; // Replace with the origin airport code
const DESTINATION = 'LAX'; // Replace with the destination airport code
const CURRENCY = 'USD'; // Replace with the currency code you want to use
async function getFlightPrices() {
const url = `https://skyscanner-skyscanner-flight-search-v1.p.rapidapi.com/apiservices/browsequotes/v1.0/US/${CURRENCY}/en-US/${ORIGIN}-sky/${DESTINATION}-sky/anytime`;
try {
const response = await axios.get(url, {
headers: {
'X-RapidAPI-Key': API_KEY,
},
});
const data = response.data;
const quotes = data.Quotes;
// Print the flight prices
console.log(`Flight prices from ${ORIGIN} to ${DESTINATION}:`);
quotes.forEach((quote) => {
console.log(`${quote.OutboundLeg.DepartureDate}: ${quote.MinPrice} ${CURRENCY}`);
});
} catch (error) {
console.error(error);
}
}
getFlightPrices();