-
Notifications
You must be signed in to change notification settings - Fork 3
/
AirLabsAPI
32 lines (25 loc) · 897 Bytes
/
AirLabsAPI
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 = "9dc82e7a-00ab-4dc0-bc61-6f077199620d";
const api_base = "https://airlabs.co/api/v9/";
function apiCall(url, cb) {
axios.get(`${api_base}${url}`)
.then(response => {
cb(null, response, response.data);
})
.catch(error => {
cb(error, null, null);
});
}
// Add your new filter parameters here
const newFilterParams = {
dep_iata: "SFO", // Replace with the actual departure airport code
arr_iata: "JFK", // Replace with the actual arrival airport code
};
const queryString = Object.entries(newFilterParams)
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
.join("&");
const flightEndpoint = `flights?_view=array&_fields=hex,flag,lat,lng,dir,alt&${queryString}`;
const apiKeyParam = `&api_key=${api_key}`;
apiCall(`${flightEndpoint}${apiKeyParam}`, (err, res, body) => {
console.log(body);
});