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

Problems using web API to set body fat percentage

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
0 Votes
1 REPLY 1

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

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