04-20-2019 17:48
04-20-2019 17:48
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?
Answered! Go to the Best Answer.
04-23-2019 17:53
04-23-2019 17:53
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.
04-23-2019 17:53
04-23-2019 17:53
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.
04-23-2019 21:34
04-23-2019 21:34
Awesome! Thanks Gordon.