2

I am building a travel booking site using Amadeus self service web-service. I have come to a point where I want to the users to be able to search perform a relative search for a city or airport using the actual name instead of IATA codes since. The problem is that the Amadeus API doesn't really solve this problem for me. This is like this because the request process requires me ton include a country code as part of the request parameters. is there anyway I can achieve this without the countryCode field?

After Including the Access Token in the header. I get this. https://i.stack.imgur.com/9OqZn.png

```async function airportAndCitySearch(keyword) {
  console.log("Searching " + keyword);
  var form = new FormData();
  var settings = {
    "url": "https://test.api.amadeus.com/v1/reference-data/locations?subType=CITY,AIRPORT&keyword=" + keyword + "&countryCode=DE",
    "method": "GET",
    "timeout": 0,
    "processData": false,
    "mimeType": "multipart/form-data",
    "contentType": false,
    "data": form
  };```

I manage to get the Access Token with this request.

  console.log("Requesting Token...");
  var settings = {
    "url": "https://test.api.amadeus.com/v1/security/oauth2/token",
    "method": "POST",
    "timeout": 0,
    "data": {
      "client_id": CLIENT_ID,
      "client_secret": CLIENT_SECRET,
      "grant_type": "client_credentials"
    }
  };

  $.ajax(settings).done(function (response) {
    console.log("Assigning Token variables...");
    ACCESS_TOKEN = response.access_token;
    console.log("Access Token : " + ACCESS_TOKEN);
  });
}






CliffTheCoder
  • 394
  • 1
  • 4
  • 24

1 Answers1

3

Amadeus has an endpoint that doesn't require country code.

Endpoint:

GET https://test.api.amadeus.com/v1/reference-data/locations?subType=AIRPORT,CITY&keyword=r&page[limit]=5

See here the definition: https://developers.amadeus.com/self-service/category/air/api-doc/airport-and-city-search/api-reference

Example:

https://test.api.amadeus.com/v1/reference-data/locations?subType=CITY,AIRPORT&keyword=paris&page[limit]=5

Answer: https://pastebin.com/efrmUiYs

Diogo Peres
  • 1,302
  • 1
  • 11
  • 20
  • I have take a look at the DOC. When I run it i get an error 401 unathorised. I am can guess that this has something to do with providing an Access token or CLIENT_KEY and CLIENT_SECRET, but there is no where in the sample code where I can do this. I am able to acquire the Access token in another request though. Look at the post update above. – CliffTheCoder Sep 23 '19 at 09:39
  • The authorization has to go on the message's header. Check this thread: https://stackoverflow.com/questions/50080663/amadeus-api-authentication/50086620#50086620 – Diogo Peres Sep 23 '19 at 09:49
  • I have, I am now getting HTTP status 200 OK but with no data in the response. – CliffTheCoder Sep 23 '19 at 09:58
  • Have you tried to use the API Explorer that Amadeus provide? Insert the url that you are calling and check if it is supposed to return data – Diogo Peres Sep 23 '19 at 10:03
  • Adding the header did it. I followed the thread you shared and just copied the entire thing whilst changing a few variable names. It's working now. THANKS – CliffTheCoder Sep 23 '19 at 10:22
  • @DiogoPeres Is there a way to get the full list of Airport IATA Codes? Without the search query param? – Usman Sabuwala Nov 25 '22 at 16:32