Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create a meal using the API return emtpy array and I don't understand why.

ANSWERED

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

 

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

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!

View best answer in original post

Best Answer
3 REPLIES 3

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 Answer
0 Votes

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!

Best Answer

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.

Best Answer