10-13-2023 05:39 - edited 10-13-2023 06:09
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-13-2023 05:39 - edited 10-13-2023 06:09
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I am using the intraday api after having received the relevant authorisation.
However, when I make api calls to fitbit, some users (it doesn't seem to happen to everyone) receive them status code 401.
To give you a bit more context, I am using the api calls from a mobile app made in flutter and the fitbitter package, which does not handle intraday calls but I have adapted it, everything seems to work in the test environment, only some users have this problem and I can't understand why.
There is the url i m calling:
'https://api.fitbit.com/1/user/${fitbitCredentials.userID}/activities/${resourceToString[resource]}/date/$startDateStr/$endDateStr/1min/time/$startTimeStr/$endTimeStr.json'
For example my complete url is:
'https://api.fitbit.com/1/user/AAAAA/activities/steps/date/yyyy-mm-dd/yyyy-mm-dd/1min/time/15:45/23:59.json'
The two dates are same day for intraday api constraints
Answered! Go to the Best Answer.
Accepted Solutions
10-18-2023 05:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-18-2023 05:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Yes, I have already received authorisation.
I have discovered that there is a problem with the flutter library for the fitbit I am using in that it does not regenerate the tokens correctly, so for the first 8 hours it works, then failing to regenerate the token it makes calls with an expired token, the 401 is definitely due to this.
Thank you very much for your support.

10-13-2023 12:23
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


10-13-2023 12:23
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I think you might get a 401 if the user hasn't provided permission for your app to access the data you're requesting.
Some intraday data need Fitbit approval (see here).
Gondwana Software

10-15-2023 08:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-15-2023 08:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Thank you for your reply.
I have actually already done this step with my app and received permission to use this type of api. is there perhaps an extra step to take when I call api to have my app recognised as authorised for intraday?

10-15-2023 11:57
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


10-15-2023 11:57
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
The only reason I can think of for intermittent 401s would be for users who haven't authorised your app's use of the specific data you're trying to access.
Gondwana Software
10-16-2023 09:52
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-16-2023 09:52
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I will try to investigate this, I too cannot honestly explain it, I will ask to my users. Thank you for your reply.

10-16-2023 12:22
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



10-16-2023 12:22
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Hi @Kirus
At 401 can be caused by several things. See https://dev.fitbit.com/build/reference/web-api/troubleshooting-guide/error-messages/#401-unauthorize.... The most common issues are
- expired token
- user hasn't consented to share the activity data
- application doesn't have intraday access
The access tokens have a lifespan of 8 hours. Once they expire, you need to use the refresh token to obtain a new access token/refresh token pair. Along with verifying the user consented to activity, have you verified if the access token is still active?
Gordon
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google
10-17-2023 02:21
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-17-2023 02:21
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Before each api call the library automatically checks if the token has expired and if so it is regenerated. Surely this is not the third case, I am investigating with my users to see if they have given authorisation. The alternative is that the library does not regenerate the token correctly, I will check this too.
Thank you very much for your help.

10-17-2023 11:27
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



10-17-2023 11:27
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Just to confirm the 3rd scenario is not an issue, have you applied for intraday access and gotten approval?
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google

10-18-2023 05:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-18-2023 05:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Yes, I have already received authorisation.
I have discovered that there is a problem with the flutter library for the fitbit I am using in that it does not regenerate the tokens correctly, so for the first 8 hours it works, then failing to regenerate the token it makes calls with an expired token, the 401 is definitely due to this.
Thank you very much for your support.

