07-11-2024 03:25
07-11-2024 03:25
I'm using the endpoint API to retrieve my Fitbit data. All seems okay except that, since yesterday (possibly earlier than that, as I have been on holiday), using the endpoints for retrieving calories and steps returns no data.
For example:
https://api.fitbit.com/1/user/-/activities/calories/date/YYYY-MM-DD/1d.json
returns no data.
Yesterday, this worked about 10% of the time, but returned no data the other 90% of the time. Today, this returns no data all the time.
This issue also arises when trying to retrieve data (steps, calories, heart rate) from individual exercise activities.
Why is this happening??
07-11-2024 19:37
07-11-2024 20:26
07-11-2024 20:26
Hi @mrchurch
I tested the endpoint using the Web API Explorer tool and I was able to get data back. What are the dates that you're querying, and are you sure the data exists? Are you getting an error or just an empty response?
07-12-2024 01:09
07-12-2024 01:09
07-12-2024 02:07
07-12-2024 02:07
So I've investigated further, and the problem lies in the fact that the JSON returned by the calories and steps endpoints is now "prettified" (i.e. it has been formatted using newlines and spaces to be human-readable). Before now, the JSON returned contained no formatting white space.
It would appear that the JSON library I am using cannot cope with such formatting whitespace.
It also didn't help that those two endpoints also used to return the intraday data when requesting a single day's data - but now doesn't. That was an easy fix, I now use the endpoint as follows:
https://api.fitbit.com/1/user/-/activities/calories/date/YYYY-MM-DD/1d/1min.json
However, that still returns JSON containing formatting whitespace.
Thanks for your help...
07-12-2024 02:34
07-12-2024 02:34
I'm pretty sure that the various endpoints are contracted to return the JSON data as a "single line of JSON" (i.e. with no formatting whitespace) in order to minimise the size of the data packet being returned.
It turns out that my application has been written on the understanding that this is the case. Indeed, every other endpoint honours this contract ... so why are these different? Is it a bug?
I mean, I could change my app so that it removes the formatting whitespace before handing the JSON over to the back-end processing unit, but that seems like ME having to counter an API bug...
---
My application has been written to consider the returned data to be valid if and only if it is a single non-empty line of text. If it is zero lines or two or more lines, it is thus considered invalid data.
Sure, this is an over-robust requirement (in theory), but it has never failed me before now. And, as indicated in my first post, two days ago, the endpoints were honouring the "single-line JSON" contract on about 10% of all requests. So, this looks like a deliberate change being made by the Fitbit developers to no longer deliver unformatted JSON...