Skip to content

Commit 945e706

Browse files
committed
Node SDK: updated examples
1 parent 26d3bdf commit 945e706

File tree

49 files changed

+1648
-1324
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1648
-1324
lines changed
Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
var Amadeus = require("amadeus");
2-
var amadeus = new Amadeus({
3-
clientId: 'YOUR_API_KEY',
4-
clientSecret: 'YOUR_API_SECRET'
1+
const Amadeus = require("amadeus");
2+
3+
const amadeus = new Amadeus({
4+
clientId: "YOUR_API_KEY",
5+
clientSecret: "YOUR_API_SECRET",
56
});
67

7-
// What's the airline name for the IATA code BA?
8-
amadeus.referenceData.airlines.get({
9-
airlineCodes: 'BA'
10-
}).then(function (response) {
11-
console.log(response);
12-
}).catch(function (response) {
13-
console.error(response);
14-
});
8+
async function main() {
9+
try {
10+
// What's the airline name for the IATA code BA?
11+
const response = await amadeus.referenceData.airlines.get({
12+
airlineCodes: "BA",
13+
});
14+
console.log(response);
15+
} catch (error) {
16+
console.error(error);
17+
}
18+
}
19+
20+
main();
Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1-
const Amadeus = require('amadeus');
1+
const Amadeus = require("amadeus");
22

3-
var amadeus = new Amadeus({
4-
clientId: 'YOUR_AMADEUS_API_KEY',
5-
clientSecret: 'YOUR_AMADEUS_API_SECRET'
3+
const amadeus = new Amadeus({
4+
clientId: "YOUR_AMADEUS_API_KEY",
5+
clientSecret: "YOUR_AMADEUS_API_SECRET",
66
});
7-
// Or `var amadeus = new Amadeus()` if the environment variables are set
7+
// Or `const amadeus = new Amadeus()` if the environment variables are set
88

9+
async function main() {
10+
try {
11+
// What are the destinations served by the British Airways (BA)?
12+
const response = await amadeus.airline.destinations.get({
13+
airlineCode: "BA",
14+
});
915

10-
// What are the destinations served by the British Airways (BA)?
11-
amadeus.airline.destinations.get({airlineCode: 'BA'})
12-
.then(response => console.log(response))
13-
.catch(err => console.error(err));
16+
console.log(response);
17+
} catch (error) {
18+
console.error(error);
19+
}
20+
}
21+
22+
main();
Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
var Amadeus = require("amadeus");
2-
var amadeus = new Amadeus({
3-
clientId: 'YOUR_API_KEY',
4-
clientSecret: 'YOUR_API_KEY'
1+
const Amadeus = require("amadeus");
2+
3+
const amadeus = new Amadeus({
4+
clientId: "YOUR_API_KEY",
5+
clientSecret: "YOUR_API_KEY",
56
});
67

7-
// Retrieve information about the LHR airport?
8-
amadeus.referenceData.location('ALHR').get()
9-
.then(function (response) {
8+
async function main() {
9+
try {
10+
// Retrieve information about the LHR airport?
11+
const response = await amadeus.referenceData.location("ALHR").get();
12+
1013
console.log(response);
11-
}).catch(function (response) {
12-
console.error(response);
13-
});
14+
} catch (error) {
15+
console.error(error);
16+
}
17+
}
18+
19+
main();
Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
var Amadeus = require("amadeus");
2-
var amadeus = new Amadeus({
3-
clientId: 'YOUR_API_KEY',
4-
clientSecret: 'YOUR_API_SECRET'
1+
const Amadeus = require("amadeus");
2+
3+
const amadeus = new Amadeus({
4+
clientId: "YOUR_API_KEY",
5+
clientSecret: "YOUR_API_SECRET",
56
});
67

7-
// Which cities or airports start with ’r'?
8-
amadeus.referenceData.locations.get({
9-
keyword: 'r',
10-
subType: Amadeus.location.any
11-
}).then(function (response) {
12-
console.log(response);
13-
}).catch(function (response) {
14-
console.error(response);
15-
});
8+
async function main() {
9+
try {
10+
// Which cities or airports start with ’r'?
11+
const response = await amadeus.referenceData.locations.get({
12+
keyword: "r",
13+
subType: Amadeus.location.any,
14+
});
15+
16+
console.log(response);
17+
} catch (error) {
18+
console.error(error);
19+
}
20+
}
21+
22+
main();
Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
var Amadeus = require("amadeus");
2-
var amadeus = new Amadeus({
3-
clientId: 'YOUR_API_KEY',
4-
clientSecret: 'YOUR_API_SECRET'
1+
const Amadeus = require("amadeus");
2+
3+
const amadeus = new Amadeus({
4+
clientId: "YOUR_API_KEY",
5+
clientSecret: "YOUR_API_SECRET",
56
});
67

7-
// What relevant airports are there around a specific location?
8-
amadeus.referenceData.locations.airports.get({
9-
longitude: 2.55,
10-
latitude: 49.0000
11-
}).then(function (response) {
12-
console.log(response);
13-
}).catch(function (response) {
14-
console.error(response);
15-
});
8+
async function main() {
9+
try {
10+
// What relevant airports are there around a specific location?
11+
const response = await amadeus.referenceData.locations.airports.get({
12+
longitude: 2.55,
13+
latitude: 49.0,
14+
});
15+
16+
console.log(response);
17+
} catch (error) {
18+
console.error(error);
19+
}
20+
}
21+
22+
main();
Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
var Amadeus = require("amadeus");
2-
var amadeus = new Amadeus({
3-
clientId: 'YOUR_API_KEY',
4-
clientSecret: 'YOUR_API_SECRET'
1+
const Amadeus = require("amadeus");
2+
3+
const amadeus = new Amadeus({
4+
clientId: "YOUR_API_KEY",
5+
clientSecret: "YOUR_API_SECRET",
56
});
67

7-
// Will there be a delay in the JFK airport on the 1st of September?
8-
amadeus.airport.predictions.onTime.get({
9-
airportCode: 'JFK',
10-
date: '2022-09-01'
11-
}).then(function (response) {
12-
console.log(response);
13-
}).catch(function (response) {
14-
console.error(response);
15-
});
8+
async function main() {
9+
try {
10+
// Will there be a delay in the JFK airport on the 1st of September?
11+
const response = await amadeus.airport.predictions.onTime.get({
12+
airportCode: "JFK",
13+
date: "2022-09-01",
14+
});
15+
16+
console.log(response);
17+
} catch (error) {
18+
console.error(error);
19+
}
20+
}
21+
22+
main();
Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1-
var Amadeus = require("amadeus");
2-
var amadeus = new Amadeus({
3-
clientId: 'YOUR_API_KEY',
4-
clientSecret: 'YOUR_API_SECRET'
5-
});
1+
const Amadeus = require("amadeus");
62

7-
// Find all destinations served by CDG Airport
8-
amadeus.airport.directDestinations.get({
9-
departureAirportCode: 'MAD',
10-
}).catch(function (response) {
11-
console.error(response);
3+
const amadeus = new Amadeus({
4+
clientId: "YOUR_API_KEY",
5+
clientSecret: "YOUR_API_SECRET",
126
});
7+
8+
async function main() {
9+
try {
10+
// Find all destinations served by CDG Airport
11+
const response = await amadeus.airport.directDestinations.get({
12+
departureAirportCode: "MAD",
13+
});
14+
15+
console.log(response);
16+
} catch (error) {
17+
console.error(error);
18+
}
19+
}
20+
21+
main();
Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,39 @@
1-
var Amadeus = require("amadeus");
2-
var amadeus = new Amadeus({
3-
clientId: 'YOUR_AMADEUS_API_KEY',
4-
clientSecret: 'YOUR_AMADEUS_API_SECRET'
1+
const Amadeus = require("amadeus");
2+
3+
const amadeus = new Amadeus({
4+
clientId: "YOUR_AMADEUS_API_KEY",
5+
clientSecret: "YOUR_AMADEUS_API_SECRET",
56
});
67

8+
async function main() {
9+
try {
10+
// Search flights from LON to DEL
11+
const flightOffersResponse = await amadeus.shopping.flightOffersSearch.get({
12+
originLocationCode: "LON",
13+
destinationLocationCode: "DEL",
14+
departureDate: "2023-06-01",
15+
returnDate: "2023-06-30",
16+
adults: "1",
17+
});
718

8-
// Search flights from LON to DEL
9-
amadeus.shopping.flightOffersSearch.get({
10-
originLocationCode: 'LON',
11-
destinationLocationCode: 'DEL',
12-
departureDate: '2023-06-01',
13-
returnDate: '2023-06-30',
14-
adults: '1'
15-
//then Get branded fares available from the first offer
16-
}).then(function (flightOffersResponse) {
17-
return amadeus.shopping.flightOffers.upselling.post(
18-
JSON.stringify({
19-
"data": {
20-
"type": "flight-offers-upselling",
21-
"flightOffers": [
22-
flightOffersResponse.data[0]
23-
],
24-
"payments": [
19+
//then Get branded fares available from the first offer
20+
const response = await amadeus.shopping.flightOffers.upselling.post({
21+
data: {
22+
type: "flight-offers-upselling",
23+
flightOffers: [flightOffersResponse.data[0]],
24+
payments: [
2525
{
26-
"brand": "VISA_IXARIS",
27-
"binNumber": 123456,
28-
"flightOfferIds": [
29-
1
30-
]
31-
}
32-
]
33-
}
34-
})
35-
);
36-
}).then(function (response) {
37-
console.log(response);
38-
}).catch(function (response) {
39-
console.error(response);
40-
});
26+
brand: "VISA_IXARIS",
27+
binNumber: 123456,
28+
flightOfferIds: [1],
29+
},
30+
],
31+
},
32+
});
33+
console.log(response);
34+
} catch (error) {
35+
console.error(error);
36+
}
37+
}
38+
39+
main();
Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1-
var Amadeus = require("amadeus");
2-
var amadeus = new Amadeus({
3-
clientId: 'YOUR_API_KEY',
4-
clientSecret: 'YOUR_API_SECRET'
5-
});
1+
const Amadeus = require("amadeus");
62

7-
// finds cities that match a specific word or string of letters.
8-
// Return a list of cities matching a keyword 'Paris'
9-
amadeus.referenceData.locations.cities.get({
10-
keyword: 'Paris'
11-
}).catch(function (response) {
12-
console.error(response);
3+
const amadeus = new Amadeus({
4+
clientId: "YOUR_API_KEY",
5+
clientSecret: "YOUR_API_SECRET",
136
});
7+
8+
async function main() {
9+
try {
10+
// Finds cities that match a specific word or string of letters.
11+
// Return a list of cities matching a keyword 'Paris'
12+
const response = await amadeus.referenceData.locations.cities.get({
13+
keyword: "Paris",
14+
});
15+
16+
console.log(response);
17+
} catch (error) {
18+
console.error(error);
19+
}
20+
}
21+
22+
main();

0 commit comments

Comments
 (0)