首页 > 解决方案 > Amadeus City and Airports Location API 自动完成系统

问题描述

我正在将自动完成系统添加到我正在开发的预订网站。我了解自动完成系统从预先填充的数据中获取。所以我正在尝试从 https://test.api.amadeus.com/v1/reference-data/locations获取位置/机场代码以查看所有位置的列表这样我就可以设计自动完成系统,但我得到了不好的响应,我的应用程序缺少一个重要参数。我正在尝试显示位置列表。我希望有人能指出我哪里出错了。

"use_strict";
function getLocations(){
 let url = "https://test.api.amadeus.com/v1/reference-data/locations";  
 fetch(url,{
     method:"GET",
     headers:{
         "Content-Type":"application/json",
         "Authorization":"Bearer BgRWNa48WGmqPowlRCMvIwHt6a96"
     },
     mode:"cors",
     catch:"default"
 }).then(function(response){
         return response.json();
 }).then(function(data){
     console.log(data);
 }).catch(function(error){
     console.log(error);
 });
}

getLocations(); 

**

:对象{状态:400,代码:32171,标题:“强制性数据丢失”,...}

** ​</p>

标签: javascriptsearchfetchamadeuscity

解决方案


您缺少必需的查询参数。根据API 参考,需要subType(AIRPORT 或 CITY)和keyword参数。例如:

https://test.api.amadeus.com/v1/reference-data/locations?subType=AIRPORT&keyword=LON

将返回名称中包含关键字的机场列表LON(伦敦希思罗机场、伦敦盖特威克机场、伦敦斯坦斯特德机场等)


推荐阅读