Amadeus航班API错误:航空公司代码应为2或3个字母数字,除了YY和YYY。

huangapple go评论116阅读模式
英文:

Amadeus flights API error: carrier code is a 2 or 3 alphanum except YY and YYY

问题

我正在使用以下SDK通过Amadeus搜索和购买航班:

https://github.com/autotune/amadeus/pull/1/files

这是一个之前被放弃的项目,我决定接手并使其正常工作。作为该项目的一部分,我正在尝试在沙盒环境中购买机票,并遇到以下错误:

{
  "errors": [
    {
      "code": 477,
      "title": "INVALID FORMAT",
      "detail": "carrier code is a 2 or 3 alphanum except YY and YYY",
      "source": {
        "pointer": "/data/flightOffers[0]/itineraries[1]/segments[0]/operating/carrierCode",
        "example": "AF"
      },
      "status": 400
    }
  ]
}

这是发送的JSON数据:

{
  "type": "flight-order",
  "travelers": [
    {
      "id": "1",
      "dateOfBirth": "1990-02-15",
      "name": {
        "firstName": "Foo",
        "lastName": "Bar"
      },
      "gender": "MALE",
      "contact": {
        "emailAddress": "foo@bar.com",
        "phones": [
          {
            "deviceType": "MOBILE",
            "countryCallingCode": "33",
            "number": "5555555555"
          }
        ]
      }
    }
  ],
  "ticketingAgreement": {
    "option": "DELAY_TO_CANCEL",
    "delay": "6D"
  },
  "remarks": {},
  "operating": {
    "carrierCode": "UA"
  }
}

希望能得到帮助!

英文:

I am using the following SDK to search for and purchase flights via Amadeus:

https://github.com/autotune/amadeus/pull/1/files

This was a previously abandoned project I have decided to take on and make work. As part of that project I am trying to purchase a ticket in the sandbox environment and getting the following error:

{
  "errors": [
    {
      "code": 477,
      "title": "INVALID FORMAT",
      "detail": "carrier code is a 2 or 3 alphanum except YY and YYY",
      "source": {
        "pointer": "/data/flightOffers[0]/itineraries[1]/segments[0]/operating/carrierCode",
        "example": "AF"
      },
      "status": 400
    }
  ]
}

Here is the json data being sent:

{
  "type": "flight-order",
  "travelers": [
    {
      "id": "1",
      "dateOfBirth": "1990-02-15",
      "name": {
        "firstName": "Foo",
        "lastName": "Bar"
      },
      "gender": "MALE",
      "contact": {
        "emailAddress": "foo@bar.com",
        "phones": [
          {
            "deviceType": "MOBILE",
            "countryCallingCode": "33",
            "number": "5555555555"
          }
        ]
      }
    }
  ],
  "ticketingAgreement": {
    "option": "DELAY_TO_CANCEL",
    "delay": "6D"
  },
  "remarks": {},
  "operating": {
    "carrierCode": "UA"
  }
}

Any help appreciated!

答案1

得分: 2

错误提示表明发送的有效负载无效。我建议您使用类似Curl或Postman的工具来验证您是否使用了正确的API文档,然后再调试实际的代码。

英文:

The error suggests that the sent payload is invalid. I'd advice you use a tool like Curl or Postman to verify you're using the right API documentation, before debugging actual code.

答案2

得分: 1

在进一步阅读您的PR并检查API参考文档后:

https://developers.amadeus.com/self-service/category/air/api-doc/flight-create-orders/api-reference

我认为您需要确认传递的航空公司代码是否在以下部分的航段中可用:

flightOffers > itineraries > segments

尽管API参考文档中没有像您在发送的数据中使用的operating > carrierCode,但我猜测根据您分享的API错误响应,他们正在对传递的航班报价进行检查。

我建议您检查调用flightOffers时获取的结果,并将其添加到发送到沙盒的有效负载中。

英文:

After further reading your PR and checking the API reference at :

https://developers.amadeus.com/self-service/category/air/api-doc/flight-create-orders/api-reference

I think you need to confirm that the Carrier code being passed is available in the segments under:

flightOffers > itineraries > segments

Although the API reference doesn't have operating > carrierCode like you used in the data sent, my guess after seeing the API error response you shared is that they are performing a check against the flight offers passed.

I suggest you check the results gotten when you call the flightOffers and also add it to the payload sent to the sandbox.

huangapple
  • 本文由 发表于 2022年5月31日 03:16:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/72439103.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定