0

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.

4
  • Have you tried url encoding the query in postman? Commented Mar 12, 2023 at 10:17
  • @Jamie_D Yes, I have already tried EncodeURLComponent, but it's not working. Commented Mar 12, 2023 at 13:38
  • No. This issue is not solved yet. Commented Mar 13, 2023 at 12:46
  • Updated as answer ... Commented Mar 14, 2023 at 21:43

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.