05-10-2021 16:44
05-10-2021 16:44
I am trying to make this works using CURL call, from a php server.
I can authorize my user, get the token, fetch profiles, units, ingredients.... all this works but now I want to push on fitbit a new meal created from selected ingredients, quantity and units.
I end with an empty array, no error, just an empty array.
From what I read in the doc, empty array is used on deleting, but not creating. I should receive the meal just created...
any ideas ? I just can't understand and that's drive me crazy!
Thank you
Answered! Go to the Best Answer.
05-14-2021 10:44
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
05-14-2021 10:44
Hi @spoulin23.
Thanks for your patience. After speaking with engineering, it seems that we are incorrectly entering the parameter values into the URL instead of the body of the request.
I retested the endpoint and entered the parameters into the body, and I was able to successfully create the meal:
curl -X POST "https://api.fitbit.com/1/user/-/meals.json" \ -H "accept: application/json" \ -H "authorization: Bearer (access_token)" \ -H "Content-Type: application/json" \ --data '{"name":"Breakfast","description":"Banana","mealFoods":[{"foodId":81000,"amount":1,"unitId":147}]}' \ -v
Response:
{
"meal": {
"description": "Banana",
"id": 383590338,
"mealFoods": [
{
"accessLevel": "PUBLIC",
"amount": 1,
"brand": "",
"calories": 1,
"foodId": 81000,
"locale": "en_US",
"mealTypeId": 7,
"name": "Banana",
"unit": {
"id": 147,
"name": "gram",
"plural": "grams"
},
"units": [
16,
121,
120,
304,
319,
204,
179,
91,
256,
279,
226,
180,
147,
389
]
}
],
"name": "Breakfast"
}
}
Due to the confusion, I'll file a ticket to update our public API documentation to specify how the parameters should be used for this endpoint.
I hope this helps, and thanks again for bring this to our attention!
05-11-2021 16:33
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
05-11-2021 16:33
Hi @spoulin23,
Welcome to the forums!
Thanks for reporting this, I was able to reproduce the issue and this looks like a bug to me. I'm going to file a ticket with engineering and have this looked into. I'll keep you in the loop as I get updates.
Thanks!
Best Answer05-14-2021 10:44
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
05-14-2021 10:44
Hi @spoulin23.
Thanks for your patience. After speaking with engineering, it seems that we are incorrectly entering the parameter values into the URL instead of the body of the request.
I retested the endpoint and entered the parameters into the body, and I was able to successfully create the meal:
curl -X POST "https://api.fitbit.com/1/user/-/meals.json" \ -H "accept: application/json" \ -H "authorization: Bearer (access_token)" \ -H "Content-Type: application/json" \ --data '{"name":"Breakfast","description":"Banana","mealFoods":[{"foodId":81000,"amount":1,"unitId":147}]}' \ -v
Response:
{
"meal": {
"description": "Banana",
"id": 383590338,
"mealFoods": [
{
"accessLevel": "PUBLIC",
"amount": 1,
"brand": "",
"calories": 1,
"foodId": 81000,
"locale": "en_US",
"mealTypeId": 7,
"name": "Banana",
"unit": {
"id": 147,
"name": "gram",
"plural": "grams"
},
"units": [
16,
121,
120,
304,
319,
204,
179,
91,
256,
279,
226,
180,
147,
389
]
}
],
"name": "Breakfast"
}
}
Due to the confusion, I'll file a ticket to update our public API documentation to specify how the parameters should be used for this endpoint.
I hope this helps, and thanks again for bring this to our attention!
05-14-2021 10:48
05-14-2021 10:48
Hi. thanks for this reply.
I was also also able to create a meal with the API, after many tries.... I am not sure what I missed at first, but for sure, the empty answer was not very helpful 😉
Thanks for your support.