Hi!
I'm trying to POST a body fat percentage to my Fitbit account via the Fitbit web API. This is the code I'm using:
function setBodyFatPercentage(access_token, date, bodyFatPercentageValue){
fetch('https://api.fitbit.com/1/user/-/body/log/fat.json', {
method: 'POST',
headers: {
Authorization: `Bearer ${access_token}`,
'Content-Type': 'application/json',
'Accept': 'application/json, text/plain, */*'
},
body: JSON.stringify({
fat: bodyFatPercentageValue,
date: date
})
})
.then(res => res.json())
.then(res => {
console.log(JSON.stringify({
fat: bodyFatPercentageValue,
date: date
}) );
console.log(`res2 setBodyFatPercentage: ${JSON.stringify(res)}`);
})
.catch(err => {
console.error('Error: ', err);
});
}And here is the response I'm getting:
{"errors":[{"errorType":"validation","fieldName":"fat","message":"Fat is required"}]}
I found one guy that seemed to have the same problem in 2017, but no one answered him: https://community.fitbit.com/t5/Web-API-Development/Add-body-fat-through-fitbit-web-application/td-p...
Best Answer
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.
Hi @thamyB
Make certain when you're building your API endpoint to POST a body fat percentage, that the final string looks similar to
https://api.fitbit.com/1/user/-/body/log/fat.json?fat=20&date=2021-03-25&time=09%3A00
the parameters are query parameters, not body parameters
Gordon
Best Answer