09-07-2020 17:45
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-07-2020 17:45
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hi All I wrote a Fitbit App before and I am trying my luck with an application.
I can get the request token, and I can use it to get the access token. I cannot use the access token to get the actual data. Below is just some rough work and I will be properly storing the tokens later, just trying to get the foundation working.
router.get('/fitbit-api-token',function(req,res) {
const requestToken = req.query.code
const headers = {
'Authorization': `Basic REDACTED`,
'Content-Type': 'application/x-www-form-urlencoded',
};
const body = "cliend_id=REDACTED&grant_type=authorization_code&redirect_uri=http://localhost:3000/fitbit-api-token&code="+requestToken;
request({
url: 'https://api.fitbit.com/oauth2/token',
method: 'POST',
headers,
body,
},function (error, response, body){
const fitbitResponse = JSON.parse(body)
access_token = fitbitResponse.access_token;
refresh_token = fitbitResponse.refresh_token;
user_id = fitbitResponse.user_id;
var json_headers = {
'Authorization': 'Bearer ' + access_token,
};
console.log(json_headers);
request({
url: "https://api.fitbit.com/1/user/"+ user_id + "/activities/heart/date/today/1d.json",
method: 'GET',
json_headers,
},function (error, response, body){
console.log(body);
});
});
I get an authorization error: Invalid Authorization token type when I am doing the GET method
09-08-2020 15:59
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



09-08-2020 15:59
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hi @vanmepper
I'm not familiar with the programming language you're using. I'm not sure if this has anything to do with your error, but I do see the word client_id misspelled in your code for the variable "body". The misspelling could cause the /oauth2/token call to fail would which not provide you with an access token. Are you sure you're getting the access token, refresh token and user id from the endpoint?
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google

09-08-2020 16:09
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-08-2020 16:09
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
@Gordon-C I am using Javascript.
I was still getting tokens which is weird. It doesn't return any errors and it appears to be correct. I did fix client_id and that doesnt change anything.
Below is the response I get with some details edited out.

09-09-2020 13:07
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-09-2020 13:07
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
@GordonFitbit I just tried using Postman and I get the expected response so it seems to be on my request side and not a token error. I will have to look into it more.

09-09-2020 17:27
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-09-2020 17:27
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I used a different function called fetch and used the mode set to 'cors' and that seemed to fix it.

