I am trying to fetch data from Nutritionix API to get the nutrition data by food name. I succesfully fetched foods by search keyword but my second request fails. Here's the test code(xxx is just placeholder):
async function getNutrition() {
const response = await fetch(`https://trackapi.nutritionix.com/v2/natural/nutrients`, {
method: 'POST',
headers: {
'x-app-id': 'xxx',
'x-app-key': 'xxx',
'x-remote-user-id': '0',
},
body: {
'query':'apple'
}
})
const data = await response.json()
return data
}
I have tried the same with JSON.stringify too but the error message is the same: "child "query" fails because ["query" is required]", id: "7323ff62-a995-4112-8a61-7f7f758d7cd8"
I hope someone can help me with this. I'm at the very beginning of using APIs and it is a little bit confusing for me.