Postman – Nutritionix API Error – "message": "child \"query\" fails because [\"query\" is required]"

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

Postman - Nutritionix API Error - "message": "child \"query\" fails because [\"query\" is required]"

问题

我只是尝试使用自然语言发送一个Nutritionix API的POST请求来计算各种锻炼消耗的卡路里,用于测试该API,我正在使用Postman。

您可以访问GitHub资源以查看请求和响应:Nutritionix API v2: Natural Exercise Endpoint Sample

POST https://trackapi.nutritionix.com/v2/natural/exercise
POST请求体:

{
 "query": "Ran 2 miles and walked for 3Km.",
 "gender": "male",
 "weight_kg": 72,
 "height_cm": 160,
 "age": 23
}
请求头:

- x-app-id
- x-app-key
- Content-Type: application/json

当我尝试使用这些数据发送请求时,我得到了400 Bad Request的错误消息。我查找了这个错误,有些人说尝试移除Content-Type: application/json,但在请求头中推荐了Content-Type,无论是否移除,都会继续出现相同的错误,如下所示:

{
    "message": "child \"query\" fails because [\"query\" is required]",
    "id": "2a84d18c-8afc-4f22-9278-2e1bc385621b"
}

我只想获得200 OK的响应,但我不知道如何修复这个问题。如果有人能帮助我解决这个问题,对我会很有帮助。

英文:

I am just trying to make calories burned for various exercises using natural language by sending a post request by Nutritionix API and for testing the API, I am using Postman.

Here you can visit the github resouces for request and response: Nutritionix API v2: Natural Exercise Endpoint Sample

POST https://trackapi.nutritionix.com/v2/natural/exercise
POST request body:

{
 "query": "Ran 2 miles and walked for 3Km.",
 "gender": "male",
 "weight_kg": 72,
 "height_cm": 160,
 "age": 23
}
Headers:

- x-app-id
- x-app-key
- Content-Type: application/json

When I tried to send request by using these data, am getting error message with 400 Bad Request. I look up on to this error some says try removing the Content-Type: application/json, but Content-Type was recommended in the headers thread, with or without it the same error continues as follows:

{
    "message": "child \"query\" fails because [\"query\" is required]",
    "id": "2a84d18c-8afc-4f22-9278-2e1bc385621b"
}

Postman – Nutritionix API Error – "message": "child \"query\" fails because [\"query\" is required]"

Postman – Nutritionix API Error – "message": "child \"query\" fails because [\"query\" is required]"

Postman – Nutritionix API Error – "message": "child \"query\" fails because [\"query\" is required]"

I just want to get the response 200 OK. But I don't know how to fix that part. It would be useful for me if I got any help on this matter.

答案1

得分: 1

看起来你正在尝试使用URL中的查询参数查询练习端点。API文档示例 指定查询应位于请求主体中:

Postman – Nutritionix API Error – "message": "child \"query\" fails because [\"query\" is required]"

请注意,在图像中,URL中没有查询参数...

确保选择JSON作为类型。

除此之外,只要你有正确的API密钥,你的标头部分看起来很好...

英文:

It looks like you're trying to query the exercise endpoint with a query parameter in the URL. The API documentation example specifies that the query should be located in the body of the request:

Postman – Nutritionix API Error – "message": "child \"query\" fails because [\"query\" is required]"

Note in the image there are no query parameters in the URL ...

Make sure you choose JSON as the type.

Other than that your header section looks good as long as you have the right API keys ....

huangapple
  • 本文由 发表于 2023年3月12日 15:38:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/75711695.html
匿名

发表评论

匿名网友

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

确定