John Davidson

php - error when using Amadeus get started guide for Javascript

0 comments
Message:


I am new to Amadeus and am currently stuck at the first step. I am using the test URL (test.api.amadeus.com) When I use the example code with my API key and API secret, I get the following:


ClientError

Below is the backend code I used with the key and secret:


const express = require('express');
const Amadeus = require('amadeus');

const app = express();
const amadeus = new Amadeus({
clientId: '{API key}',
clientSecret: '{API secret}'
});

amadeus.shopping.flightOffersSearch.get({
originLocationCode: 'SYD',
destinationLocationCode: 'BKK',
departureDate: '2022-06-01',
adults: '2'
}).then(function(response){
console.log(response.data);
}).catch(function(responseError){
console.log(responseError.code);
});


app.use(express.static('client'));

app.listen(8080);

No issues on the express side.


I can get my access token using the curl command on the "get started" guide, however when I run the below curl command I get this error:


command:


curl -X GET 'https://test.api.amadeus.com/v1/shopping/flight-destinations?origin=PAR&maxPrice=200' -H 'Authorization: Bearer {{token}}'

response


{
"errors": [
{
"code": 38190,
"title": "Invalid access token",
"detail": "The access token provided in the Authorization header is invalid",
"status": 401
}
]
}

Any help will be appreciated. I can't seem to see where I have gone wrong



My Answer:
It looks like the issue might be with how you are passing the access token in the Authorization header in your curl command. Instead of using double curly braces {{token}}, you should use single curly braces {token} to pass the actual access token value.

Try updating your curl command to the following:

bash
curl -X GET 'https://test.api.amadeus.com/v1/shopping/flight-destinations?origin=PAR&maxPrice=200' -H 'Authorization: Bearer {token}'


Make sure to replace {token} with the actual access token value that you obtained using the curl command in the "get started" guide.

If you continue to experience issues, double-check that you are using the correct API key and secret in your backend code and that you are obtaining and passing the access token correctly in your curl command.

Rate this post

4 of 5 based on 5167 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us