DEV Community

Discussion on: Export Mi Band 5 data from Mi Fit to Google Sheets

Collapse
 
zont_zo_it_x profile image
midas

Thanks for sharing! I am looking to use this for a school project. Problem is, I am getting this error after trying to sync in google sheets:

TypeError: Cannot read property 'tp' of undefined

Do you have any idea how I can fix this?

Collapse
 
palms profile image
Guilherme Palmerio

Found it!

The error you're encountering indicates an attempt to access the 'tp' property of something that is undefined. In your code, this happens on the line where you try to access element.summary.pai.tp:

Change:
var totalPai = element.summary.pai.tp;

To:
var totalPai = element.summary.pai && element.summary.pai.tp ? element.summary.pai.tp : '';

Apparently, the element.summary.pai object is undefined in some cases, leading to the mentioned error. To fix this, you can add checks to ensure that the properties are present before accessing them.