尝试使用 API 拒绝 Uber Eats 优食订单时出现错误 400:“无法解析 json”

问题描述 投票:0回答:1

我正在将 Uber Eats 优食拒绝订单功能集成到我们的系统中,并遵循拒绝订单的官方文档。但是,我遇到了 400 Bad Request 错误,并显示 JSON 无法解析的消息。我确保我的请求符合文档的规范,包括提供有效的拒绝原因对象。

这是我发送的请求正文:

{
  "deny_reason": {
    "info": "Item is not available",
    "type": "ITEM_ISSUE",
    "client_error_code": 408,
    "item_metadata": {
      "invalid_item": [
        {
          "id": "2022",
          "type": "NOT_ON_MENU",
          "client_error_code": 408,
          "info": "Broken oven.",
          "external_id": "chz_piz_18"
        }
      ]
    }
  }
}

我收到的错误消息是“Error: 400. Could not parse json”:

{"error":"Could not parse json: merchant_orders_presentation.DenyOrderRequest.DenyReason: merchant_orders_presentation.RejectionReason.ClientErrorCode: ReadString: expects \" or n, but found 4, error found in #10 byte of ...|or_code\":408,\"item_m|..., bigger context ...|available\",\"type\":\"ITEM_ISSUE\",\"client_error_code\":408,\"item_metadata\":{\"invalid_item\":[{\"id\":\"2022\",\"|...}"}

我已经密切关注https://developer.uber.com/docs/eats/references/api/order_suite#tag/DenyOrder提供的文档,但我不确定为什么会遇到此解析错误。 client_error_code 指定为整数,我的 JSON 结构与给出的示例匹配。

有人以前遇到过这个问题或者可以发现我可能做错了什么吗?任何指导或建议将不胜感激。

json error-handling uber-api http-status-code-400
1个回答
0
投票

该问题似乎源于 Uber Eats API 文档中的差异。尽管文档建议

client_error_code
应为整数,但将其作为字符串 (
"408"
) 而不是整数 (
408
) 提交可以解决该错误。

"client_error_code": "408",

将请求正文中的

client_error_code
更改为字符串可以让 API 成功处理请求。这表明 API 期望
client_error_code
作为字符串,与文档相反。

© www.soinside.com 2019 - 2024. All rights reserved.