apipostpostman

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


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 - Params

Postman - Nutritionix API - Headers

Postman - Nutritionix API - Result

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.


Solution

  • 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:

    enter image description here

    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 ....