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

Error 401

ANSWERED

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

 

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

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.

View best answer in original post

Best Answer
0 Votes
8 REPLIES 8

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).

Peter McLennan
Gondwana Software
Best Answer
0 Votes

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?

Best Answer
0 Votes

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.

Peter McLennan
Gondwana Software
Best Answer

I will try to investigate this, I too cannot honestly explain it, I will ask to my users. Thank you for your reply.

Best Answer
0 Votes

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

  1. expired token
  2. user hasn't consented to share the activity data
  3. 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

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

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.

Best Answer
0 Votes

Just to confirm the 3rd scenario is not an issue, have you applied for intraday access and gotten approval?

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

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.

Best Answer
0 Votes