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

Cannot add new food using the web api

ANSWERED

I've been trying to add new food through the create food API, however, it keeps complaining about missing required fields even though I'm adding just the right fields:

 

CURL Request:
curl -d '{"defaultFoodMeasurementUnitId": 304,"defaultServingSize":1,"calories":324, "name":"SPans-Eggs"}' -i -H "Authorization: Bearer TOKEN" -X POST https://api.fitbit.com/1/user/-/foods.json

CURL Response:

HTTP/2 400
date: Sun, 21 Apr 2019 00:27:12 GMT
content-type: application/json;charset=UTF-8
vary: Origin,Accept-Encoding
cache-control: no-cache, private
content-language: en
fitbit-rate-limit-limit: 150
fitbit-rate-limit-remaining: 136
fitbit-rate-limit-reset: 1968
x-frame-options: SAMEORIGIN
x-frame-options: SAMEORIGIN
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
server: cloudflare
cf-ray: 4cab3b1acc419613-SJC

{"errors":[{"errorType":"validation","fieldName":"defaultServingSize","message":"Default Serving Size is required."},{"errorType":"validation","fieldName":"name","message":"Food name is required."},{"errorType":"validation","fieldName":"defaultFoodMeasurementUnitId","message":"Default food measurement unit id is required."}]}

 

What'd I miss? 

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

Hi @rb512 

 

I just tested creating the food within the Web API Explorer using the values you provided and it worked.

 

curl -X POST "https://api.fitbit.com/1/user/-/foods.json?name=SPans-Eggs&defaultFoodMeasurementUnitId=304&defaultS..." -H "accept: application/json" -H "authorization: Bearer <access_token>"

 

I don't think we support the syntax of sending the parameters as a JSON string using the -d flag.

Gordon Crenshaw
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google

View best answer in original post

Best Answer
2 REPLIES 2

Hi @rb512 

 

I just tested creating the food within the Web API Explorer using the values you provided and it worked.

 

curl -X POST "https://api.fitbit.com/1/user/-/foods.json?name=SPans-Eggs&defaultFoodMeasurementUnitId=304&defaultS..." -H "accept: application/json" -H "authorization: Bearer <access_token>"

 

I don't think we support the syntax of sending the parameters as a JSON string using the -d flag.

Gordon Crenshaw
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google
Best Answer

Awesome! Thanks Gordon.

Best Answer
0 Votes